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();
}
}
}
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);
}
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();
}
}
}
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);
}
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;
}
Aggregations