FIXMessageParser { public boolean parse(ByteBuffer buffer) throws IOException { boolean garbled; while (true) { buffer.mark(); int beginning = buffer.position(); if (buffer.remaining() < 2) return false; garbled = buffer.get() != '8' || buffer.get() != '='; if (!beginString.get(buffer)) { buffer.reset(); return false; } if (garbled) continue; int position = buffer.position(); if (buffer.remaining() < 2) { buffer.reset(); return false; } garbled = buffer.get() != '9' || buffer.get() != '='; if (!bodyLength.get(buffer)) { buffer.reset(); return false; } if (garbled) { buffer.position(position); continue; } int length = (int)bodyLength.asInt(); if (buffer.remaining() < length + 7) { buffer.reset(); return false; } position = buffer.position(); if (checkSumEnabled && !acceptCheckSum(buffer, beginning, position, length)) continue; int limit = buffer.limit(); buffer.limit(position + length); garbled = message.get(buffer) == false; buffer.limit(limit); buffer.position(position + length + 7); if (garbled) continue; listener.message(message); return true; } } FIXMessageParser(FIXConfig config, FIXMessageListener listener); boolean parse(ByteBuffer buffer);  }
@Test public void readGarbledCheckSumCheckSumDisabled() throws IOException { ByteBuffer buffer = ByteBuffers.wrap("8=FIX.4.2\u00019=5\u000135=D\u000110=000\u0001"); assertEquals(true, parse(buffer, false)); assertEquals(0, buffer.remaining()); assertEquals(asList("35=D\u0001"), messages.collect()); }
@Test public void read() throws IOException { ByteBuffer buffer = ByteBuffers.wrap("8=FIX.4.2\u00019=5\u000135=D\u000110=181\u0001"); assertEquals(true, parse(buffer, true)); assertEquals(0, buffer.remaining()); assertEquals(asList("35=D\u0001"), messages.collect()); }
@Test public void readFixt11() throws IOException { ByteBuffer buffer = ByteBuffers.wrap("8=FIXT.1.1\u00019=5\u000135=D\u000110=005\u0001"); assertEquals(true, parse(buffer, true)); assertEquals(0, buffer.remaining()); assertEquals(asList("35=D\u0001"), messages.collect()); }