Search in sources :

Example 1 with Ir

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

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

the class GenerateFixBinaryTest method shouldGenerateValidJava.

@Test
public void shouldGenerateValidJava() 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 JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager);
    outputManager.setPackageName(ir.applicableNamespace());
    generator.generateMessageHeaderStub();
    generator.generateTypeStubs();
    generator.generate();
    final Map<String, CharSequence> sources = outputManager.getSources();
    final String className = "MDIncrementalRefreshTradeSummary42Decoder";
    final String fqClassName = ir.applicableNamespace() + "." + className;
    final Class<?> aClass = CompilerUtil.compileInMemory(fqClassName, sources);
    assertNotNull(aClass);
}
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) Ir(uk.co.real_logic.sbe.ir.Ir) Test(org.junit.Test)

Example 3 with Ir

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

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

the class JsonPrinterTest method exampleMessagePrintedAsJson.

@Test
public void exampleMessagePrintedAsJson() throws Exception {
    final ByteBuffer encodedSchemaBuffer = ByteBuffer.allocateDirect(SCHEMA_BUFFER_CAPACITY);
    encodeSchema(encodedSchemaBuffer);
    final ByteBuffer encodedMsgBuffer = ByteBuffer.allocateDirect(MSG_BUFFER_CAPACITY);
    encodeTestMessage(encodedMsgBuffer);
    encodedSchemaBuffer.flip();
    final Ir ir = decodeIr(encodedSchemaBuffer);
    final JsonPrinter printer = new JsonPrinter(ir);
    final String result = printer.print(encodedMsgBuffer);
    assertEquals("{\n" + "    \"serialNumber\": 1234,\n" + "    \"modelYear\": 2013,\n" + "    \"someNumbers\": [0, 1, 2, 3, 4],\n" + "    \"vehicleCode\": \"abcdef\",\n" + "    \"capacity\": 2000,\n" + "    \"numCylinders\": 4,\n" + "    \"maxRpm\": 9000,\n" + "    \"manufacturerCode\": \"123\",\n" + "    \"fuel\": Petrol,\n" + "    \"fuelFigures\": [\n" + "    {\n" + "        \"speed\": 30,\n" + "        \"mpg\": 35.9\n" + "    },\n" + "    {\n" + "        \"speed\": 55,\n" + "        \"mpg\": 49.0\n" + "    },\n" + "    {\n" + "        \"speed\": 75,\n" + "        \"mpg\": 40.0\n" + "    }],\n" + "    \"performanceFigures\": [\n" + "    {\n" + "        \"octaneRating\": 95,\n" + "        \"acceleration\": [\n" + "        {\n" + "            \"mph\": 30,\n" + "            \"seconds\": 4.0\n" + "        },\n" + "        {\n" + "            \"mph\": 60,\n" + "            \"seconds\": 7.5\n" + "        },\n" + "        {\n" + "            \"mph\": 100,\n" + "            \"seconds\": 12.2\n" + "        }]\n" + "    },\n" + "    {\n" + "        \"octaneRating\": 99,\n" + "        \"acceleration\": [\n" + "        {\n" + "            \"mph\": 30,\n" + "            \"seconds\": 3.8\n" + "        },\n" + "        {\n" + "            \"mph\": 60,\n" + "            \"seconds\": 7.1\n" + "        },\n" + "        {\n" + "            \"mph\": 100,\n" + "            \"seconds\": 11.8\n" + "        }]\n" + "    }],\n" + "    \"manufacturer\": \"Honda\",\n" + "    \"model\": \"Civic VTi\",\n" + "    \"activationCode\": \"\"\n" + "}", result);
}
Also used : Ir(uk.co.real_logic.sbe.ir.Ir) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with Ir

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

the class IrGenerator method generate.

/**
 * Generate a complete {@link uk.co.real_logic.sbe.ir.Ir} for a given schema.
 *
 * @param schema    from which the {@link uk.co.real_logic.sbe.ir.Ir} should be generated.
 * @param namespace for the generated code.
 * @return complete {@link uk.co.real_logic.sbe.ir.Ir} for a given schema.
 */
public Ir generate(final MessageSchema schema, final String namespace) {
    this.schema = schema;
    final List<Token> headerTokens = generateForHeader(schema);
    final Ir ir = new Ir(schema.packageName(), namespace, schema.id(), schema.version(), schema.semanticVersion(), schema.byteOrder(), headerTokens);
    for (final Message message : schema.messages()) {
        final long msgId = message.id();
        ir.addMessage(msgId, generateForMessage(schema, msgId));
    }
    return ir;
}
Also used : Ir(uk.co.real_logic.sbe.ir.Ir) Token(uk.co.real_logic.sbe.ir.Token)

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