use of uk.co.real_logic.sbe.otf.TokenListener in project simple-binary-encoding by real-logic.
the class CompositeElementsGenerationTest method shouldOtfDecodeCorrectly.
@Test
public void shouldOtfDecodeCorrectly() throws Exception {
final ByteBuffer encodedSchemaBuffer = ByteBuffer.allocate(SCHEMA_BUFFER_CAPACITY);
encodeSchema(encodedSchemaBuffer);
final ByteBuffer encodedMsgBuffer = ByteBuffer.allocate(MSG_BUFFER_CAPACITY);
encodeTestMessage(encodedMsgBuffer);
encodedSchemaBuffer.flip();
final Ir ir = decodeIr(encodedSchemaBuffer);
final DirectBuffer decodeBuffer = new UnsafeBuffer(encodedMsgBuffer);
final OtfHeaderDecoder otfHeaderDecoder = new OtfHeaderDecoder(ir.headerStructure());
assertThat(otfHeaderDecoder.getBlockLength(decodeBuffer, 0), is(22));
assertThat(otfHeaderDecoder.getSchemaId(decodeBuffer, 0), is(3));
assertThat(otfHeaderDecoder.getTemplateId(decodeBuffer, 0), is(1));
assertThat(otfHeaderDecoder.getSchemaVersion(decodeBuffer, 0), is(0));
final TokenListener mockTokenListener = mock(TokenListener.class);
OtfMessageDecoder.decode(decodeBuffer, otfHeaderDecoder.encodedLength(), MSG_ENCODER.sbeSchemaVersion(), MSG_ENCODER.sbeBlockLength(), ir.getMessage(MSG_ENCODER.sbeTemplateId()), mockTokenListener);
final InOrder inOrder = inOrder(mockTokenListener);
inOrder.verify(mockTokenListener).onBeginComposite(any(), any(), eq(2), eq(17));
inOrder.verify(mockTokenListener).onEnum(any(), eq(decodeBuffer), eq(8), any(), eq(3), eq(6), eq(0));
inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(9), any(), eq(0));
inOrder.verify(mockTokenListener).onBitSet(any(), eq(decodeBuffer), eq(10), any(), eq(8), eq(12), eq(0));
inOrder.verify(mockTokenListener).onBeginComposite(any(), any(), eq(13), eq(16));
inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(14), any(), eq(0));
inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(22), any(), eq(0));
inOrder.verify(mockTokenListener).onEndComposite(any(), any(), eq(13), eq(16));
inOrder.verify(mockTokenListener).onEndComposite(any(), any(), eq(2), eq(17));
}
Aggregations