Search in sources :

Example 1 with IrGenerator

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

the class CompositeElementsGenerationTest method encodeSchema.

private static void encodeSchema(final ByteBuffer buffer) throws Exception {
    final Path path = Paths.get("src/test/resources/composite-elements-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();
        }
    }
}
Also used : Path(java.nio.file.Path) IrEncoder(uk.co.real_logic.sbe.ir.IrEncoder) IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Ir(uk.co.real_logic.sbe.ir.Ir)

Example 2 with IrGenerator

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

the class GenerateFixBinaryTest method shouldGenerateValidJava.

@Test
public void shouldGenerateValidJava() 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 JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager);
    outputManager.setPackageName(ir.applicableNamespace());
    generator.generateMessageHeaderStub();
    generator.generateTypeStubs();
    generator.generate();
    final Map<String, CharSequence> sources = outputManager.getSources();
    final String className = "MDIncrementalRefreshTradeSummary42Decoder";
    final String fqClassName = ir.applicableNamespace() + "." + className;
    final Class<?> aClass = CompilerUtil.compileInMemory(fqClassName, sources);
    assertNotNull(aClass);
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) ParserOptions(uk.co.real_logic.sbe.xml.ParserOptions) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Ir(uk.co.real_logic.sbe.ir.Ir) Test(org.junit.Test)

Example 3 with IrGenerator

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

the class SchemaExtensionTest method setup.

@Before
public void setup() throws Exception {
    final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
    final MessageSchema schema = parse(TestUtil.getLocalResource("extension-schema.xml"), options);
    final IrGenerator irg = new IrGenerator();
    ir = irg.generate(schema);
    outputManager.clear();
    outputManager.setPackageName(ir.applicableNamespace());
    generator().generate();
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) ParserOptions(uk.co.real_logic.sbe.xml.ParserOptions) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Before(org.junit.Before)

Example 4 with IrGenerator

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

the class CompositeElementsIrTest method shouldGenerateCorrectIrForCompositeWithRefSchema.

@Test
public void shouldGenerateCorrectIrForCompositeWithRefSchema() 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(3);
    final Token beginCompositeToken = tokens.get(2);
    final Token mantissaToken = tokens.get(3);
    final Token exponentToken = tokens.get(4);
    final Token enumToken = tokens.get(5);
    final Token endCompositeToken = tokens.get(9);
    assertThat(beginCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
    assertThat(beginCompositeToken.name(), is("futuresPrice"));
    assertThat(beginCompositeToken.encodedLength(), is(11));
    assertThat(mantissaToken.signal(), is(Signal.ENCODING));
    assertThat(mantissaToken.name(), is("mantissa"));
    assertThat(mantissaToken.offset(), is(0));
    assertThat(mantissaToken.encoding().primitiveType(), is(PrimitiveType.INT64));
    assertThat(exponentToken.signal(), is(Signal.ENCODING));
    assertThat(exponentToken.name(), is("exponent"));
    assertThat(exponentToken.offset(), is(8));
    assertThat(exponentToken.encoding().primitiveType(), is(PrimitiveType.INT8));
    assertThat(enumToken.signal(), is(Signal.BEGIN_ENUM));
    assertThat(enumToken.encodedLength(), is(1));
    assertThat(enumToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
    assertThat(enumToken.offset(), is(10));
    assertThat(endCompositeToken.signal(), is(Signal.END_COMPOSITE));
    assertThat(endCompositeToken.name(), is("futuresPrice"));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Test(org.junit.Test)

Example 5 with IrGenerator

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

the class CompositeElementsIrTest method shouldGenerateCorrectIrForCompositeElementsSchema.

@Test
public void shouldGenerateCorrectIrForCompositeElementsSchema() throws Exception {
    final MessageSchema schema = parse(getLocalResource("composite-elements-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final List<Token> tokens = ir.getMessage(1);
    final Token fieldToken = tokens.get(1);
    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(fieldToken.signal(), is(Signal.BEGIN_FIELD));
    assertThat(fieldToken.name(), is("structure"));
    assertThat(outerCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
    assertThat(outerCompositeToken.name(), is("outer"));
    assertThat(outerCompositeToken.componentTokenCount(), is(16));
    assertThat(enumToken.signal(), is(Signal.BEGIN_ENUM));
    assertThat(enumToken.name(), is("enumOne"));
    assertThat(enumToken.encodedLength(), is(1));
    assertThat(enumToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
    assertThat(enumToken.offset(), is(0));
    assertThat(enumToken.componentTokenCount(), is(4));
    assertThat(zerothToken.signal(), is(Signal.ENCODING));
    assertThat(zerothToken.offset(), is(1));
    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(2));
    assertThat(setToken.componentTokenCount(), is(5));
    assertThat(innerCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
    assertThat(innerCompositeToken.name(), is("inner"));
    assertThat(innerCompositeToken.offset(), is(6));
    assertThat(innerCompositeToken.componentTokenCount(), is(4));
    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("outer"));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Test(org.junit.Test)

Aggregations

IrGenerator (uk.co.real_logic.sbe.xml.IrGenerator)32 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)7 ParserOptions (uk.co.real_logic.sbe.xml.ParserOptions)6 IrEncoder (uk.co.real_logic.sbe.ir.IrEncoder)5 Path (java.nio.file.Path)3 BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 Before (org.junit.Before)2 IrDecoder (uk.co.real_logic.sbe.ir.IrDecoder)2 File (java.io.File)1 StringWriterOutputManager (org.agrona.generation.StringWriterOutputManager)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1