@Test public void shouldCountTagsSeparatedByMultipleSeparatorsMessage() throws UnsupportedEncodingException { given(fixTagHandler.isFinished()).willReturn(false); final byte[] msg = "8=FIX.4.2\u00019=105|35=A|34=1|49=marketm155yjtfwicmfe\u000152=20100713-17:04:39.641|56=FIX-API|95=9|96=P4ssword.|98=0\u0001108=2|141=Y|10=191|".getBytes("US-ASCII"); final byte[] logonMsg = new byte[msg.length]; System.arraycopy(msg, 0, logonMsg, 0, msg.length); final FixTagParser parser = new FixTagParser(fixTagHandler, new byte[]{1, 124}); parser.parse(logonMsg, 0, logonMsg.length, true); verify(fixTagHandler).messageStart(); verify(fixTagHandler, times(13)).onTag(any(int.class), any(byte[].class), any(int.class), any(int.class)); verify(fixTagHandler, times(13)).isFinished(); verify(fixTagHandler).messageEnd(); verifyNoMoreInteractions(fixTagHandler); }
public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } FixTagParser(final FixTagHandler fixTagHandler);  FixTagParser(final FixTagHandler fixTagHandler, final byte[] lineSeparators); }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } FixTagParser(final FixTagHandler fixTagHandler);  FixTagParser(final FixTagHandler fixTagHandler, final byte[] lineSeparators); boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure); }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } FixTagParser(final FixTagHandler fixTagHandler);  FixTagParser(final FixTagHandler fixTagHandler, final byte[] lineSeparators); boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure); static final byte SOH; }