use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class ValueRefsTest method shouldGenerateValueRefToEnum.
@Test
public void shouldGenerateValueRefToEnum() throws Exception {
final MessageSchema schema = parse(getLocalResource("value-ref-schema.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
assertThat(ir.getMessage(1).get(2).encodedLength(), is(8));
assertThat(ir.getMessage(2).get(2).encodedLength(), is(0));
assertThat(ir.getMessage(3).get(2).encodedLength(), is(0));
assertThat(ir.getMessage(4).get(2).encodedLength(), is(0));
assertThat(ir.getMessage(5).get(2).encodedLength(), is(0));
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class JavaGeneratorTest method setUp.
@Before
public void setUp() throws Exception {
final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
final MessageSchema schema = parse(TestUtil.getLocalResource("code-generation-schema.xml"), options);
final IrGenerator irg = new IrGenerator();
ir = irg.generate(schema);
outputManager.clear();
outputManager.setPackageName(ir.applicableNamespace());
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class ConstantCharArrayTest method shouldGenerateConstCharArrayMethods.
@Test
public void shouldGenerateConstCharArrayMethods() throws Exception {
final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
final MessageSchema schema = parse(TestUtil.getLocalResource("issue505.xml"), options);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final StringWriterOutputManager outputManager = new StringWriterOutputManager();
outputManager.setPackageName(ir.applicableNamespace());
final JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager);
generator.generate();
final String sources = outputManager.getSources().toString();
final String expectedOne = " public byte sourceOne()\n" + " {\n" + " return (byte)67;\n" + " }";
assertThat(sources, containsString(expectedOne));
final String expectedTwo = " public byte sourceTwo()\n" + " {\n" + " return (byte)68;\n" + " }";
assertThat(sources, containsString(expectedTwo));
final String expectedThree = " public String sourceThree()\n" + " {\n" + " return \"EF\";\n" + " }";
assertThat(sources, containsString(expectedThree));
final String expectedFour = " public String sourceFour()\n" + " {\n" + " return \"GH\";\n" + " }";
assertThat(sources, containsString(expectedFour));
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class GenerateFixBinaryTest method shouldGenerateAndEncodeIr.
@Test
public void shouldGenerateAndEncodeIr() throws Exception {
System.setProperty(SbeTool.KEYWORD_APPEND_TOKEN, "_");
final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
final MessageSchema schema = parse(TestUtil.getLocalResource("FixBinary.xml"), options);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
final IrEncoder irEncoder = new IrEncoder(buffer, ir);
irEncoder.encode();
buffer.flip();
final IrDecoder irDecoder = new IrDecoder(buffer);
final Ir decodedIr = irDecoder.decode();
assertEquals(ir.id(), decodedIr.id());
assertEquals(ir.version(), decodedIr.version());
assertEquals(ir.byteOrder(), decodedIr.byteOrder());
assertEquals(ir.applicableNamespace(), decodedIr.applicableNamespace());
assertEquals(ir.packageName(), decodedIr.packageName());
assertEquals(ir.types().size(), decodedIr.types().size());
assertEquals(ir.messages().size(), decodedIr.messages().size());
}
use of uk.co.real_logic.sbe.xml.IrGenerator in project simple-binary-encoding by real-logic.
the class CompositeElementsIrTest method shouldGenerateCorrectIrForCompositeElementsWithOffsetsSchemaRc4.
@Test
public void shouldGenerateCorrectIrForCompositeElementsWithOffsetsSchemaRc4() throws Exception {
final MessageSchema schema = parse(getLocalResource("composite-elements-schema-rc4.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final List<Token> tokens = ir.getMessage(2);
final Token outerCompositeToken = tokens.get(2);
final Token enumToken = tokens.get(3);
final Token zerothToken = tokens.get(7);
final Token setToken = tokens.get(8);
final Token innerCompositeToken = tokens.get(13);
final Token firstToken = tokens.get(14);
final Token secondToken = tokens.get(15);
final Token endOuterCompositeToken = tokens.get(17);
assertThat(outerCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(outerCompositeToken.name(), is("outerWithOffsets"));
assertThat(outerCompositeToken.encodedLength(), is(32));
assertThat(enumToken.signal(), is(Signal.BEGIN_ENUM));
assertThat(enumToken.encodedLength(), is(1));
assertThat(enumToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
assertThat(enumToken.offset(), is(2));
assertThat(zerothToken.signal(), is(Signal.ENCODING));
assertThat(zerothToken.offset(), is(3));
assertThat(zerothToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
assertThat(setToken.signal(), is(Signal.BEGIN_SET));
assertThat(setToken.name(), is("setOne"));
assertThat(setToken.encodedLength(), is(4));
assertThat(setToken.encoding().primitiveType(), is(PrimitiveType.UINT32));
assertThat(setToken.offset(), is(8));
assertThat(innerCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(innerCompositeToken.name(), is("inner"));
assertThat(innerCompositeToken.offset(), is(16));
assertThat(firstToken.signal(), is(Signal.ENCODING));
assertThat(firstToken.name(), is("first"));
assertThat(firstToken.offset(), is(0));
assertThat(firstToken.encoding().primitiveType(), is(PrimitiveType.INT64));
assertThat(secondToken.signal(), is(Signal.ENCODING));
assertThat(secondToken.name(), is("second"));
assertThat(secondToken.offset(), is(8));
assertThat(secondToken.encoding().primitiveType(), is(PrimitiveType.INT64));
assertThat(endOuterCompositeToken.signal(), is(Signal.END_COMPOSITE));
assertThat(endOuterCompositeToken.name(), is("outerWithOffsets"));
}
Aggregations