Search in sources :

Example 16 with IrGenerator

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));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) Test(org.junit.Test)

Example 17 with IrGenerator

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());
}
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 18 with IrGenerator

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));
}
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) StringWriterOutputManager(org.agrona.generation.StringWriterOutputManager) Ir(uk.co.real_logic.sbe.ir.Ir) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 19 with IrGenerator

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());
}
Also used : IrEncoder(uk.co.real_logic.sbe.ir.IrEncoder) 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) IrDecoder(uk.co.real_logic.sbe.ir.IrDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 20 with IrGenerator

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"));
}
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