use of uk.co.real_logic.sbe.xml.MessageSchema 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.xml.MessageSchema 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.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class SchemaExtensionTest method setup.
@Before
public void setup() throws Exception {
final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
final MessageSchema schema = parse(TestUtil.getLocalResource("extension-schema.xml"), options);
final IrGenerator irg = new IrGenerator();
ir = irg.generate(schema);
outputManager.clear();
outputManager.setPackageName(ir.applicableNamespace());
generator().generate();
}
use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class CompositeElementsIrTest method shouldGenerateCorrectIrForCompositeWithRefSchema.
@Test
public void shouldGenerateCorrectIrForCompositeWithRefSchema() throws Exception {
final MessageSchema schema = parse(getLocalResource("composite-elements-schema-rc4.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final List<Token> tokens = ir.getMessage(3);
final Token beginCompositeToken = tokens.get(2);
final Token mantissaToken = tokens.get(3);
final Token exponentToken = tokens.get(4);
final Token enumToken = tokens.get(5);
final Token endCompositeToken = tokens.get(9);
assertThat(beginCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(beginCompositeToken.name(), is("futuresPrice"));
assertThat(beginCompositeToken.encodedLength(), is(11));
assertThat(mantissaToken.signal(), is(Signal.ENCODING));
assertThat(mantissaToken.name(), is("mantissa"));
assertThat(mantissaToken.offset(), is(0));
assertThat(mantissaToken.encoding().primitiveType(), is(PrimitiveType.INT64));
assertThat(exponentToken.signal(), is(Signal.ENCODING));
assertThat(exponentToken.name(), is("exponent"));
assertThat(exponentToken.offset(), is(8));
assertThat(exponentToken.encoding().primitiveType(), is(PrimitiveType.INT8));
assertThat(enumToken.signal(), is(Signal.BEGIN_ENUM));
assertThat(enumToken.encodedLength(), is(1));
assertThat(enumToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
assertThat(enumToken.offset(), is(10));
assertThat(endCompositeToken.signal(), is(Signal.END_COMPOSITE));
assertThat(endCompositeToken.name(), is("futuresPrice"));
}
use of uk.co.real_logic.sbe.xml.MessageSchema in project simple-binary-encoding by real-logic.
the class CompositeElementsIrTest method shouldGenerateCorrectIrForCompositeElementsSchema.
@Test
public void shouldGenerateCorrectIrForCompositeElementsSchema() throws Exception {
final MessageSchema schema = parse(getLocalResource("composite-elements-schema.xml"), ParserOptions.DEFAULT);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final List<Token> tokens = ir.getMessage(1);
final Token fieldToken = tokens.get(1);
final Token outerCompositeToken = tokens.get(2);
final Token enumToken = tokens.get(3);
final Token zerothToken = tokens.get(7);
final Token setToken = tokens.get(8);
final Token innerCompositeToken = tokens.get(13);
final Token firstToken = tokens.get(14);
final Token secondToken = tokens.get(15);
final Token endOuterCompositeToken = tokens.get(17);
assertThat(fieldToken.signal(), is(Signal.BEGIN_FIELD));
assertThat(fieldToken.name(), is("structure"));
assertThat(outerCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(outerCompositeToken.name(), is("outer"));
assertThat(outerCompositeToken.componentTokenCount(), is(16));
assertThat(enumToken.signal(), is(Signal.BEGIN_ENUM));
assertThat(enumToken.name(), is("enumOne"));
assertThat(enumToken.encodedLength(), is(1));
assertThat(enumToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
assertThat(enumToken.offset(), is(0));
assertThat(enumToken.componentTokenCount(), is(4));
assertThat(zerothToken.signal(), is(Signal.ENCODING));
assertThat(zerothToken.offset(), is(1));
assertThat(zerothToken.encoding().primitiveType(), is(PrimitiveType.UINT8));
assertThat(setToken.signal(), is(Signal.BEGIN_SET));
assertThat(setToken.name(), is("setOne"));
assertThat(setToken.encodedLength(), is(4));
assertThat(setToken.encoding().primitiveType(), is(PrimitiveType.UINT32));
assertThat(setToken.offset(), is(2));
assertThat(setToken.componentTokenCount(), is(5));
assertThat(innerCompositeToken.signal(), is(Signal.BEGIN_COMPOSITE));
assertThat(innerCompositeToken.name(), is("inner"));
assertThat(innerCompositeToken.offset(), is(6));
assertThat(innerCompositeToken.componentTokenCount(), is(4));
assertThat(firstToken.signal(), is(Signal.ENCODING));
assertThat(firstToken.name(), is("first"));
assertThat(firstToken.offset(), is(0));
assertThat(firstToken.encoding().primitiveType(), is(PrimitiveType.INT64));
assertThat(secondToken.signal(), is(Signal.ENCODING));
assertThat(secondToken.name(), is("second"));
assertThat(secondToken.offset(), is(8));
assertThat(secondToken.encoding().primitiveType(), is(PrimitiveType.INT64));
assertThat(endOuterCompositeToken.signal(), is(Signal.END_COMPOSITE));
assertThat(endOuterCompositeToken.name(), is("outer"));
}
Aggregations