use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class CompositeRefsTest method shouldGenerateCorrectIrForCompositeRefs.
@Test
public void shouldGenerateCorrectIrForCompositeRefs() throws Exception {
final MessageSchema schema = parse(getLocalResource("issue496.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
assertNotNull(ir.getType("compositeOne"));
assertNotNull(ir.getType("compositeTwo"));
assertNotNull(ir.getType("compositeThree"));
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class GroupWithDataIrTest method shouldGenerateCorrectIrForOnlyMultipleVarDataInRepeatingGroup.
@Test
public void shouldGenerateCorrectIrForOnlyMultipleVarDataInRepeatingGroup() 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(4);
/* 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 varDataField1Token = tokens.get(9);
final Token varDataField2Token = tokens.get(15);
/* assert on the group token */
assertThat(groupToken.signal(), is(Signal.BEGIN_GROUP));
assertThat(groupToken.name(), is("Entries"));
assertThat(valueOf(groupToken.id()), is(valueOf(2)));
assertThat(varDataField1Token.signal(), is(Signal.BEGIN_VAR_DATA));
assertThat(varDataField1Token.name(), is("varDataField1"));
assertThat(valueOf(varDataField1Token.id()), is(valueOf(5)));
assertThat(varDataField2Token.signal(), is(Signal.BEGIN_VAR_DATA));
assertThat(varDataField2Token.name(), is("varDataField2"));
assertThat(valueOf(varDataField2Token.id()), is(valueOf(6)));
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class GroupWithDataIrTest method shouldGenerateCorrectIrForMultipleVarDataInRepeatingGroup.
@Test
public void shouldGenerateCorrectIrForMultipleVarDataInRepeatingGroup() 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(2);
/* 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 varDataField1Token = tokens.get(15);
final Token varDataField2Token = tokens.get(21);
/* assert on the group token */
assertThat(groupToken.signal(), is(Signal.BEGIN_GROUP));
assertThat(groupToken.name(), is("Entries"));
assertThat(valueOf(groupToken.id()), is(valueOf(2)));
assertThat(varDataField1Token.signal(), is(Signal.BEGIN_VAR_DATA));
assertThat(varDataField1Token.name(), is("varDataField1"));
assertThat(valueOf(varDataField1Token.id()), is(valueOf(5)));
assertThat(varDataField2Token.signal(), is(Signal.BEGIN_VAR_DATA));
assertThat(varDataField2Token.name(), is("varDataField2"));
assertThat(valueOf(varDataField2Token.id()), is(valueOf(6)));
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class JsonPrinterTest method encodeSchema.
private static void encodeSchema(final ByteBuffer buffer) throws Exception {
final Path path = Paths.get("src/test/resources/json-printer-test-schema.xml");
try (InputStream in = new BufferedInputStream(Files.newInputStream(path))) {
final MessageSchema schema = XmlSchemaParser.parse(in, ParserOptions.DEFAULT);
final Ir ir = new IrGenerator().generate(schema);
try (IrEncoder irEncoder = new IrEncoder(buffer, ir)) {
irEncoder.encode();
}
}
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class BasicXmlIrGenerationTest method shouldGenerateCorrectIrForBasicMessage.
@Test
public void shouldGenerateCorrectIrForBasicMessage() 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.getMessage(50001);
assertThat(valueOf(tokens.size()), is(valueOf(5)));
/* assert all elements of node 0 */
assertThat(tokens.get(0).signal(), is(Signal.BEGIN_MESSAGE));
assertThat(tokens.get(0).name(), is("TestMessage50001"));
assertThat(valueOf(tokens.get(0).id()), is(valueOf(50001)));
assertThat(valueOf(tokens.get(0).encodedLength()), is(valueOf(16)));
assertThat(valueOf(tokens.get(0).offset()), is(valueOf(0)));
/* assert all elements of node 1 */
assertThat(tokens.get(1).signal(), is(Signal.BEGIN_FIELD));
assertThat(tokens.get(1).name(), is("Tag40001"));
assertThat(valueOf(tokens.get(1).id()), is(valueOf(40001)));
assertThat(valueOf(tokens.get(1).encodedLength()), is(valueOf(0)));
assertThat(valueOf(tokens.get(1).offset()), is(valueOf(0)));
/* assert all elements of node 2 */
assertThat(tokens.get(2).signal(), is(Signal.ENCODING));
assertThat(tokens.get(2).name(), is("uint32"));
assertThat(tokens.get(2).encoding().primitiveType(), is(PrimitiveType.UINT32));
assertThat(valueOf(tokens.get(2).id()), is(valueOf(Token.INVALID_ID)));
assertThat(valueOf(tokens.get(2).encodedLength()), is(valueOf(4)));
assertThat(valueOf(tokens.get(2).offset()), is(valueOf(0)));
assertThat(tokens.get(2).encoding().byteOrder(), is(ByteOrder.LITTLE_ENDIAN));
/* assert all elements of node 3 */
assertThat(tokens.get(3).signal(), is(Signal.END_FIELD));
assertThat(tokens.get(3).name(), is("Tag40001"));
assertThat(valueOf(tokens.get(3).id()), is(valueOf(40001)));
assertThat(valueOf(tokens.get(3).encodedLength()), is(valueOf(0)));
assertThat(valueOf(tokens.get(3).offset()), is(valueOf(0)));
/* assert all elements of node 4 */
assertThat(tokens.get(4).signal(), is(Signal.END_MESSAGE));
assertThat(tokens.get(4).name(), is("TestMessage50001"));
assertThat(valueOf(tokens.get(4).id()), is(valueOf(50001)));
assertThat(valueOf(tokens.get(4).encodedLength()), is(valueOf(16)));
assertThat(valueOf(tokens.get(4).offset()), is(valueOf(0)));
}
Aggregations