Search in sources :

Example 1 with IrEncoder

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

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

the class JsonPrinterTest method encodeSchema.

private static void encodeSchema(final ByteBuffer buffer) throws Exception {
    final Path path = Paths.get("src/test/resources/json-printer-test-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 3 with IrEncoder

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

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

Example 5 with IrEncoder

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

the class OtfExample method encodeSchema.

private static void encodeSchema(final ByteBuffer byteBuffer) throws Exception {
    final Path path = Paths.get("src/main/resources/example-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(byteBuffer, 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) Ir(uk.co.real_logic.sbe.ir.Ir)

Aggregations

Ir (uk.co.real_logic.sbe.ir.Ir)5 IrEncoder (uk.co.real_logic.sbe.ir.IrEncoder)5 IrGenerator (uk.co.real_logic.sbe.xml.IrGenerator)5 MessageSchema (uk.co.real_logic.sbe.xml.MessageSchema)4 Path (java.nio.file.Path)3 BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 IrDecoder (uk.co.real_logic.sbe.ir.IrDecoder)2 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1 ParserOptions (uk.co.real_logic.sbe.xml.ParserOptions)1