Search in sources :

Example 31 with IrGenerator

use of uk.co.real_logic.sbe.xml.IrGenerator 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 32 with IrGenerator

use of uk.co.real_logic.sbe.xml.IrGenerator 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

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