Search in sources :

Example 11 with MessageSchema

use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.

the class BasicXmlIrGenerationTest method shouldGenerateCorrectIrForMessageWithVariableLengthFieldWithEmbeddedLength.

@Test
public void shouldGenerateCorrectIrForMessageWithVariableLengthFieldWithEmbeddedLength() throws Exception {
    final MessageSchema schema = parse(getLocalResource("embedded-length-and-count-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    /* 0=msg, 1=field, 2=enc, 3=fieldend, 4=field, 5=comp, 6=enc, 7=enc, 8=compend, 9=fieldend */
    final int lengthFieldIdx = 4;
    final int lengthEncIdx = 6;
    final int dataEncIdx = 7;
    final List<Token> tokens = ir.getMessage(2);
    /* assert the varDataEncoding field node is formed correctly */
    assertThat(tokens.get(lengthFieldIdx).signal(), is(Signal.BEGIN_VAR_DATA));
    assertThat(tokens.get(lengthFieldIdx).name(), is("EncryptedPassword"));
    assertThat(valueOf(tokens.get(lengthFieldIdx).id()), is(valueOf(1402)));
    /* assert the length node has correct values */
    assertThat(tokens.get(lengthEncIdx).signal(), is(Signal.ENCODING));
    assertThat(tokens.get(lengthEncIdx).encoding().primitiveType(), is(PrimitiveType.UINT8));
    /* assert the group node has the right IrId and xRefIrId, etc. */
    assertThat(tokens.get(dataEncIdx).signal(), is(Signal.ENCODING));
    assertThat(tokens.get(dataEncIdx).encoding().primitiveType(), is(PrimitiveType.CHAR));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Test(org.junit.Test)

Example 12 with MessageSchema

use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.

the class BasicXmlIrGenerationTest method shouldGenerateCorrectIrForMessageWithRepeatingGroupWithEmbeddedDimensions.

@Test
public void shouldGenerateCorrectIrForMessageWithRepeatingGroupWithEmbeddedDimensions() throws Exception {
    final MessageSchema schema = parse(getLocalResource("basic-group-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    /* 0=msg, 1=field, 2=enc, 3=fieldend, 4=group, 5=comp, 6=enc, 7=enc, 8=compend, ... */
    final int groupIdx = 4;
    final int dimensionsCompIdx = 5;
    final int dimensionsBlEncIdx = 6;
    final int dimensionsNigEncIdx = 7;
    final List<Token> tokens = ir.getMessage(1);
    /* assert on the group token */
    assertThat(tokens.get(groupIdx).signal(), is(Signal.BEGIN_GROUP));
    assertThat(tokens.get(groupIdx).name(), is("Entries"));
    assertThat(valueOf(tokens.get(groupIdx).id()), is(valueOf(2)));
    /* assert on the comp token for dimensions */
    assertThat(tokens.get(dimensionsCompIdx).signal(), is(Signal.BEGIN_COMPOSITE));
    assertThat(tokens.get(dimensionsCompIdx).name(), is("groupSizeEncoding"));
    /* assert on the enc token for dimensions blockLength */
    assertThat(tokens.get(dimensionsBlEncIdx).signal(), is(Signal.ENCODING));
    assertThat(tokens.get(dimensionsBlEncIdx).name(), is("blockLength"));
    /* assert on the enc token for dimensions numInGroup */
    assertThat(tokens.get(dimensionsNigEncIdx).signal(), is(Signal.ENCODING));
    assertThat(tokens.get(dimensionsNigEncIdx).name(), is("numInGroup"));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Test(org.junit.Test)

Example 13 with MessageSchema

use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.

the class BasicXmlIrGenerationTest method shouldGenerateCorrectIrForMessageWithVariableLengthField.

@Test
public void shouldGenerateCorrectIrForMessageWithVariableLengthField() throws Exception {
    final MessageSchema schema = parse(getLocalResource("basic-variable-length-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final List<Token> tokens = ir.getMessage(1);
    assertThat(valueOf(tokens.size()), is(valueOf(8)));
    assertThat(tokens.get(0).signal(), is(Signal.BEGIN_MESSAGE));
    assertThat(tokens.get(0).name(), is("TestMessage1"));
    assertThat(valueOf(tokens.get(0).id()), is(valueOf(1)));
    assertThat(valueOf(tokens.get(0).encodedLength()), is(valueOf(0)));
    assertThat(valueOf(tokens.get(0).offset()), is(valueOf(0)));
    assertThat(tokens.get(1).signal(), is(Signal.BEGIN_VAR_DATA));
    assertThat(tokens.get(1).name(), is("encryptedNewPassword"));
    assertThat(valueOf(tokens.get(1).id()), is(valueOf(1404)));
    assertThat(valueOf(tokens.get(1).encodedLength()), is(valueOf(0)));
    assertThat(valueOf(tokens.get(1).offset()), is(valueOf(0)));
    assertThat(tokens.get(2).signal(), is(Signal.BEGIN_COMPOSITE));
    assertThat(tokens.get(2).name(), is("varDataEncoding"));
    assertThat(valueOf(tokens.get(2).encodedLength()), is(valueOf(-1)));
    assertThat(valueOf(tokens.get(2).offset()), is(valueOf(0)));
    assertThat(tokens.get(3).signal(), is(Signal.ENCODING));
    assertThat(tokens.get(3).name(), is("length"));
    assertThat(tokens.get(3).encoding().primitiveType(), is(PrimitiveType.UINT8));
    assertThat(valueOf(tokens.get(3).id()), is(valueOf(Token.INVALID_ID)));
    assertThat(valueOf(tokens.get(3).encodedLength()), is(valueOf(1)));
    assertThat(valueOf(tokens.get(3).offset()), is(valueOf(0)));
    assertThat(tokens.get(3).encoding().byteOrder(), is(ByteOrder.LITTLE_ENDIAN));
    assertThat(tokens.get(4).signal(), is(Signal.ENCODING));
    assertThat(tokens.get(4).name(), is("varData"));
    assertThat(tokens.get(4).encoding().primitiveType(), is(PrimitiveType.CHAR));
    assertThat(valueOf(tokens.get(4).id()), is(valueOf(Token.INVALID_ID)));
    assertThat(valueOf(tokens.get(4).encodedLength()), is(valueOf(-1)));
    assertThat(valueOf(tokens.get(4).offset()), is(valueOf(1)));
    assertThat(tokens.get(4).encoding().byteOrder(), is(ByteOrder.LITTLE_ENDIAN));
    assertThat(tokens.get(5).signal(), is(Signal.END_COMPOSITE));
    assertThat(tokens.get(5).name(), is("varDataEncoding"));
    assertThat(valueOf(tokens.get(5).encodedLength()), is(valueOf(-1)));
    assertThat(valueOf(tokens.get(5).offset()), is(valueOf(0)));
    assertThat(tokens.get(6).signal(), is(Signal.END_VAR_DATA));
    assertThat(tokens.get(6).name(), is("encryptedNewPassword"));
    assertThat(valueOf(tokens.get(6).id()), is(valueOf(1404)));
    assertThat(valueOf(tokens.get(6).encodedLength()), is(valueOf(0)));
    assertThat(valueOf(tokens.get(6).offset()), is(valueOf(0)));
    assertThat(tokens.get(7).signal(), is(Signal.END_MESSAGE));
    assertThat(tokens.get(7).name(), is("TestMessage1"));
    assertThat(valueOf(tokens.get(7).id()), is(valueOf(1)));
    assertThat(valueOf(tokens.get(7).encodedLength()), is(valueOf(0)));
    assertThat(valueOf(tokens.get(7).offset()), is(valueOf(0)));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Test(org.junit.Test)

Example 14 with MessageSchema

use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.

the class CompositeOffsetsTest method shouldGenerateCorrectOffsetsForFieldsWithEmbeddedComposite.

@Test
public void shouldGenerateCorrectOffsetsForFieldsWithEmbeddedComposite() throws Exception {
    final MessageSchema schema = parse(getLocalResource("composite-offsets-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final List<Token> message2 = ir.getMessage(2);
    final int fieldOneIndex = 1;
    assertThat(message2.get(fieldOneIndex).offset(), is(0));
    assertThat(message2.get(fieldOneIndex + 1).encodedLength(), is(4));
    final int fieldTwoIndex = 4;
    assertThat(message2.get(fieldTwoIndex).offset(), is(8));
    assertThat(message2.get(fieldTwoIndex + 1).encodedLength(), is(16));
    assertThat(message2.get(fieldTwoIndex + 2).offset(), is(0));
    assertThat(message2.get(fieldTwoIndex + 2).encodedLength(), is(1));
    assertThat(message2.get(fieldTwoIndex + 3).offset(), is(8));
    assertThat(message2.get(fieldTwoIndex + 3).encodedLength(), is(8));
    final int fieldThreeIndex = 10;
    assertThat(message2.get(fieldThreeIndex).offset(), is(24));
    assertThat(message2.get(fieldThreeIndex + 1).encodedLength(), is(8));
    assertThat(message2.get(0).encodedLength(), is(32));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Test(org.junit.Test)

Example 15 with MessageSchema

use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.

the class EncodedIrTest method shouldDecodeCorrectHeader.

@Test
public void shouldDecodeCorrectHeader() throws Exception {
    final MessageSchema schema = parse(TestUtil.getLocalResource("code-generation-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final ByteBuffer buffer = ByteBuffer.allocateDirect(CAPACITY);
    final IrEncoder irEncoder = new IrEncoder(buffer, ir);
    irEncoder.encode();
    buffer.flip();
    final IrDecoder irDecoder = new IrDecoder(buffer);
    final Ir decodedIr = irDecoder.decode();
    final List<Token> tokens = decodedIr.headerStructure().tokens();
    assertThat(tokens.size(), is(ir.headerStructure().tokens().size()));
    for (int i = 0, size = tokens.size(); i < size; i++) {
        assertEqual(tokens.get(i), ir.headerStructure().tokens().get(i));
    }
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

IrGenerator (uk.co.real_logic.sbe.xml.IrGenerator)31 MessageSchema (uk.co.real_logic.sbe.xml.MessageSchema)31 Test (org.junit.Test)25 ByteBuffer (java.nio.ByteBuffer)7 Ir (uk.co.real_logic.sbe.ir.Ir)6 ParserOptions (uk.co.real_logic.sbe.xml.ParserOptions)6 IrEncoder (uk.co.real_logic.sbe.ir.IrEncoder)4 Path (java.nio.file.Path)3 BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 Before (org.junit.Before)2 StringWriterOutputManager (org.agrona.generation.StringWriterOutputManager)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 IrDecoder (uk.co.real_logic.sbe.ir.IrDecoder)1