Search in sources :

Example 1 with IrDecoder

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

use of uk.co.real_logic.sbe.ir.IrDecoder 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)2 IrDecoder (uk.co.real_logic.sbe.ir.IrDecoder)2 IrEncoder (uk.co.real_logic.sbe.ir.IrEncoder)2 IrGenerator (uk.co.real_logic.sbe.xml.IrGenerator)2 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1 MessageSchema (uk.co.real_logic.sbe.xml.MessageSchema)1 ParserOptions (uk.co.real_logic.sbe.xml.ParserOptions)1