Search in sources :

Example 6 with Ir

use of uk.co.real_logic.sbe.ir.Ir 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 7 with Ir

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

the class TargetCodeGeneratorTest method shouldLoadAndInstatiateNonStandardTargetLanguage.

@Test
public void shouldLoadAndInstatiateNonStandardTargetLanguage() throws Exception {
    final Ir ir = mock(Ir.class);
    final String outputDir = ".";
    SbeTool.generate(ir, outputDir, "uk.co.real_logic.sbe.TestTargetLanguage");
    verify(TestTargetLanguage.SINGLETON).generate();
    assertThat(ir, is(TestTargetLanguage.ir));
    assertThat(outputDir, is(TestTargetLanguage.outputDir));
}
Also used : Ir(uk.co.real_logic.sbe.ir.Ir) Test(org.junit.Test)

Example 8 with Ir

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

the class CompositeElementsGenerationTest method shouldOtfDecodeCorrectly.

@Test
public void shouldOtfDecodeCorrectly() throws Exception {
    final ByteBuffer encodedSchemaBuffer = ByteBuffer.allocate(SCHEMA_BUFFER_CAPACITY);
    encodeSchema(encodedSchemaBuffer);
    final ByteBuffer encodedMsgBuffer = ByteBuffer.allocate(MSG_BUFFER_CAPACITY);
    encodeTestMessage(encodedMsgBuffer);
    encodedSchemaBuffer.flip();
    final Ir ir = decodeIr(encodedSchemaBuffer);
    final DirectBuffer decodeBuffer = new UnsafeBuffer(encodedMsgBuffer);
    final OtfHeaderDecoder otfHeaderDecoder = new OtfHeaderDecoder(ir.headerStructure());
    assertThat(otfHeaderDecoder.getBlockLength(decodeBuffer, 0), is(22));
    assertThat(otfHeaderDecoder.getSchemaId(decodeBuffer, 0), is(3));
    assertThat(otfHeaderDecoder.getTemplateId(decodeBuffer, 0), is(1));
    assertThat(otfHeaderDecoder.getSchemaVersion(decodeBuffer, 0), is(0));
    final TokenListener mockTokenListener = mock(TokenListener.class);
    OtfMessageDecoder.decode(decodeBuffer, otfHeaderDecoder.encodedLength(), MSG_ENCODER.sbeSchemaVersion(), MSG_ENCODER.sbeBlockLength(), ir.getMessage(MSG_ENCODER.sbeTemplateId()), mockTokenListener);
    final InOrder inOrder = inOrder(mockTokenListener);
    inOrder.verify(mockTokenListener).onBeginComposite(any(), any(), eq(2), eq(17));
    inOrder.verify(mockTokenListener).onEnum(any(), eq(decodeBuffer), eq(8), any(), eq(3), eq(6), eq(0));
    inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(9), any(), eq(0));
    inOrder.verify(mockTokenListener).onBitSet(any(), eq(decodeBuffer), eq(10), any(), eq(8), eq(12), eq(0));
    inOrder.verify(mockTokenListener).onBeginComposite(any(), any(), eq(13), eq(16));
    inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(14), any(), eq(0));
    inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(22), any(), eq(0));
    inOrder.verify(mockTokenListener).onEndComposite(any(), any(), eq(13), eq(16));
    inOrder.verify(mockTokenListener).onEndComposite(any(), any(), eq(2), eq(17));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) InOrder(org.mockito.InOrder) OtfHeaderDecoder(uk.co.real_logic.sbe.otf.OtfHeaderDecoder) Ir(uk.co.real_logic.sbe.ir.Ir) TokenListener(uk.co.real_logic.sbe.otf.TokenListener) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with Ir

use of uk.co.real_logic.sbe.ir.Ir 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 10 with Ir

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

the class SbeTool method main.

/**
 * Main entry point for the SBE Tool.
 *
 * @param args command line arguments. A single filename is expected.
 * @throws Exception if an error occurs during process of the message schema.
 */
public static void main(final String[] args) throws Exception {
    if (args.length == 0) {
        System.err.format("Usage: %s <filenames>...%n", SbeTool.class.getName());
        System.exit(-1);
    }
    for (final String fileName : args) {
        final Ir ir;
        if (fileName.endsWith(".xml")) {
            final String xsdFilename = System.getProperty(SbeTool.VALIDATION_XSD);
            if (xsdFilename != null) {
                validateAgainstSchema(fileName, xsdFilename);
            }
            ir = new IrGenerator().generate(parseSchema(fileName), System.getProperty(TARGET_NAMESPACE));
        } else if (fileName.endsWith(".sbeir")) {
            ir = new IrDecoder(fileName).decode();
        } else {
            System.err.println("Input file format not supported: " + fileName);
            System.exit(-1);
            return;
        }
        final String outputDirName = System.getProperty(OUTPUT_DIR, ".");
        if (Boolean.parseBoolean(System.getProperty(GENERATE_STUBS, "true"))) {
            final String targetLanguage = System.getProperty(TARGET_LANGUAGE, "Java");
            generate(ir, outputDirName, targetLanguage);
        }
        if (Boolean.parseBoolean(System.getProperty(GENERATE_IR, "false"))) {
            final File inputFile = new File(fileName);
            final String inputFilename = inputFile.getName();
            final int nameEnd = inputFilename.lastIndexOf('.');
            final String namePart = inputFilename.substring(0, nameEnd);
            final File fullPath = new File(outputDirName, namePart + ".sbeir");
            try (IrEncoder irEncoder = new IrEncoder(fullPath.getAbsolutePath(), ir)) {
                irEncoder.encode();
            }
        }
    }
}
Also used : IrEncoder(uk.co.real_logic.sbe.ir.IrEncoder) IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) Ir(uk.co.real_logic.sbe.ir.Ir) IrDecoder(uk.co.real_logic.sbe.ir.IrDecoder) File(java.io.File)

Aggregations

Ir (uk.co.real_logic.sbe.ir.Ir)12 IrGenerator (uk.co.real_logic.sbe.xml.IrGenerator)7 Test (org.junit.Test)6 MessageSchema (uk.co.real_logic.sbe.xml.MessageSchema)6 IrEncoder (uk.co.real_logic.sbe.ir.IrEncoder)5 ByteBuffer (java.nio.ByteBuffer)4 Path (java.nio.file.Path)3 ParserOptions (uk.co.real_logic.sbe.xml.ParserOptions)3 BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)2 IrDecoder (uk.co.real_logic.sbe.ir.IrDecoder)2 Token (uk.co.real_logic.sbe.ir.Token)2 OtfHeaderDecoder (uk.co.real_logic.sbe.otf.OtfHeaderDecoder)2 File (java.io.File)1 DirectBuffer (org.agrona.DirectBuffer)1 StringWriterOutputManager (org.agrona.generation.StringWriterOutputManager)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 InOrder (org.mockito.InOrder)1 TokenListener (uk.co.real_logic.sbe.otf.TokenListener)1