use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class GroupWithDataIrTest method shouldGenerateCorrectIrForSingleVarDataInRepeatingGroup.
@Test
public void shouldGenerateCorrectIrForSingleVarDataInRepeatingGroup() throws Exception {
final MessageSchema schema = parse(getLocalResource("group-with-data-schema.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final List<Token> tokens = ir.getMessage(1);
/* 0=msg, 1=field, 2=enc, 3=fieldend, 4=group, 5=comp, 6=enc, 7=enc, 8=compend, ... */
final Token groupToken = tokens.get(4);
final Token dimensionsCompToken = tokens.get(5);
final Token dimensionsBlEncToken = tokens.get(6);
final Token varDataFieldToken = tokens.get(15);
final Token lengthEncToken = tokens.get(17);
final Token dataEncToken = tokens.get(18);
/* assert on the group token */
assertThat(groupToken.signal(), is(Signal.BEGIN_GROUP));
assertThat(groupToken.name(), is("Entries"));
assertThat(valueOf(groupToken.id()), is(valueOf(2)));
/* assert on the comp token for dimensions */
assertThat(dimensionsCompToken.signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(dimensionsCompToken.name(), is("groupSizeEncoding"));
/* assert on the enc token for dimensions blockLength */
assertThat(dimensionsBlEncToken.signal(), is(Signal.ENCODING));
assertThat(dimensionsBlEncToken.name(), is("blockLength"));
assertThat(varDataFieldToken.signal(), is(Signal.BEGIN_VAR_DATA));
assertThat(varDataFieldToken.name(), is("varDataField"));
assertThat(valueOf(varDataFieldToken.id()), is(valueOf(5)));
assertThat(lengthEncToken.signal(), is(Signal.ENCODING));
assertThat(lengthEncToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
assertThat(dataEncToken.signal(), is(Signal.ENCODING));
assertThat(dataEncToken.encoding().primitiveType(), is(PrimitiveType.CHAR));
}
use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class GroupWithDataIrTest method shouldGenerateCorrectIrForVarDataInNestedRepeatingGroup.
@Test
public void shouldGenerateCorrectIrForVarDataInNestedRepeatingGroup() throws Exception {
final MessageSchema schema = parse(getLocalResource("group-with-data-schema.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final List<Token> tokens = ir.getMessage(3);
/* 0=msg, 1=field, 2=enc, 3=fieldend, 4=group, 5=comp, 6=enc, 7=enc, 8=compend, ... */
final Token groupToken = tokens.get(4);
final Token nestedGroupToken = tokens.get(12);
final Token varDataFieldNestedToken = tokens.get(20);
final Token varDataFieldToken = tokens.get(27);
assertThat(groupToken.signal(), is(Signal.BEGIN_GROUP));
assertThat(groupToken.name(), is("Entries"));
assertThat(valueOf(groupToken.id()), is(valueOf(2)));
assertThat(nestedGroupToken.signal(), is(Signal.BEGIN_GROUP));
assertThat(nestedGroupToken.name(), is("NestedEntries"));
assertThat(valueOf(nestedGroupToken.id()), is(valueOf(4)));
assertThat(varDataFieldNestedToken.signal(), is(Signal.BEGIN_VAR_DATA));
assertThat(varDataFieldNestedToken.name(), is("varDataFieldNested"));
assertThat(valueOf(varDataFieldNestedToken.id()), is(valueOf(6)));
assertThat(varDataFieldToken.signal(), is(Signal.BEGIN_VAR_DATA));
assertThat(varDataFieldToken.name(), is("varDataField"));
assertThat(valueOf(varDataFieldToken.id()), is(valueOf(7)));
}
use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class RustGeneratorTest method generateIrForResource.
public static Ir generateIrForResource(final String localResourceName) {
final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
final String xmlLocalResourceName = localResourceName.endsWith(".xml") ? localResourceName : localResourceName + ".xml";
final MessageSchema schema;
try {
schema = parse(TestUtil.getLocalResource(xmlLocalResourceName), options);
} catch (final Exception e) {
throw new IllegalStateException(e);
}
final IrGenerator irg = new IrGenerator();
return irg.generate(schema);
}
use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class BasicXmlIrGenerationTest method shouldGenerateCorrectIrForMessageHeader.
@Test
public void shouldGenerateCorrectIrForMessageHeader() throws Exception {
final MessageSchema schema = parse(getLocalResource("basic-schema.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final List<Token> tokens = ir.headerStructure().tokens();
assertThat(valueOf(tokens.size()), is(valueOf(6)));
/* assert all elements of node 0 */
assertThat(tokens.get(0).signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(tokens.get(0).name(), is("messageHeader"));
assertThat(valueOf(tokens.get(0).id()), is(valueOf(Token.INVALID_ID)));
assertThat(valueOf(tokens.get(0).encodedLength()), is(valueOf(8)));
assertThat(valueOf(tokens.get(0).offset()), is(valueOf(0)));
/* assert all elements of node 1 */
assertThat(tokens.get(1).signal(), is(Signal.ENCODING));
assertThat(tokens.get(1).name(), is("blockLength"));
assertThat(tokens.get(1).encoding().primitiveType(), is(PrimitiveType.UINT16));
assertThat(valueOf(tokens.get(1).id()), is(valueOf(Token.INVALID_ID)));
assertThat(valueOf(tokens.get(1).encodedLength()), is(valueOf(2)));
assertThat(valueOf(tokens.get(1).offset()), is(valueOf(0)));
assertThat(tokens.get(1).encoding().byteOrder(), is(ByteOrder.LITTLE_ENDIAN));
/* assert all elements of node 2 */
assertThat(tokens.get(2).signal(), is(Signal.ENCODING));
assertThat(tokens.get(2).name(), is("templateId"));
assertThat(tokens.get(2).encoding().primitiveType(), is(PrimitiveType.UINT16));
assertThat(valueOf(tokens.get(2).id()), is(valueOf(Token.INVALID_ID)));
assertThat(valueOf(tokens.get(2).encodedLength()), is(valueOf(2)));
assertThat(valueOf(tokens.get(2).offset()), is(valueOf(2)));
assertThat(tokens.get(2).encoding().byteOrder(), is(ByteOrder.LITTLE_ENDIAN));
/* assert all elements of node 3 */
assertThat(tokens.get(3).signal(), is(Signal.ENCODING));
assertThat(tokens.get(3).name(), is("schemaId"));
assertThat(tokens.get(3).encoding().primitiveType(), is(PrimitiveType.UINT16));
assertThat(valueOf(tokens.get(3).id()), is(valueOf(Token.INVALID_ID)));
assertThat(valueOf(tokens.get(3).encodedLength()), is(valueOf(2)));
assertThat(valueOf(tokens.get(3).offset()), is(valueOf(4)));
assertThat(tokens.get(3).encoding().byteOrder(), is(ByteOrder.LITTLE_ENDIAN));
/* assert all elements of node 4 */
assertThat(tokens.get(4).signal(), is(Signal.ENCODING));
assertThat(tokens.get(4).name(), is("version"));
assertThat(tokens.get(4).encoding().primitiveType(), is(PrimitiveType.UINT16));
assertThat(valueOf(tokens.get(4).id()), is(valueOf(Token.INVALID_ID)));
assertThat(valueOf(tokens.get(4).encodedLength()), is(valueOf(2)));
assertThat(valueOf(tokens.get(4).offset()), is(valueOf(6)));
assertThat(tokens.get(4).encoding().byteOrder(), is(ByteOrder.LITTLE_ENDIAN));
/* assert all elements of node 6 */
assertThat(tokens.get(5).signal(), is(Signal.END_COMPOSITE));
assertThat(tokens.get(5).name(), is("messageHeader"));
assertThat(valueOf(tokens.get(5).id()), is(valueOf(Token.INVALID_ID)));
assertThat(valueOf(tokens.get(5).encodedLength()), is(valueOf(8)));
assertThat(valueOf(tokens.get(5).offset()), is(valueOf(0)));
}
use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class BasicXmlIrGenerationTest method shouldGenerateCorrectIrForMessageWithRepeatingGroupWithEmbeddedDimensionsDefaultDimensionType.
@Test
public void shouldGenerateCorrectIrForMessageWithRepeatingGroupWithEmbeddedDimensionsDefaultDimensionType() 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=group, 5=comp, 6=enc, 7=enc, 8=compend, 9=field, ... */
final int groupIdx = 4;
final int dimensionsCompIdx = 5;
final int fieldInGroupIdx = 9;
final List<Token> tokens = ir.getMessage(1);
assertThat(tokens.get(groupIdx).signal(), is(Signal.BEGIN_GROUP));
assertThat(tokens.get(groupIdx).name(), is("ListOrdGrp"));
assertThat(valueOf(tokens.get(groupIdx).id()), is(valueOf(73)));
assertThat(tokens.get(dimensionsCompIdx).signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(tokens.get(dimensionsCompIdx).name(), is("groupSizeEncoding"));
assertThat(tokens.get(fieldInGroupIdx).signal(), is(Signal.BEGIN_FIELD));
assertThat(tokens.get(fieldInGroupIdx).name(), is("ClOrdID"));
}
Aggregations