use of uk.co.real_logic.sbe.ir.Ir in project simple-binary-encoding by real-logic.
the class ConstantCharArrayTest method shouldGenerateConstCharArrayMethods.
@Test
public void shouldGenerateConstCharArrayMethods() throws Exception {
final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
final MessageSchema schema = parse(TestUtil.getLocalResource("issue505.xml"), options);
final IrGenerator irg = new IrGenerator();
final Ir ir = irg.generate(schema);
final StringWriterOutputManager outputManager = new StringWriterOutputManager();
outputManager.setPackageName(ir.applicableNamespace());
final JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager);
generator.generate();
final String sources = outputManager.getSources().toString();
final String expectedOne = " public byte sourceOne()\n" + " {\n" + " return (byte)67;\n" + " }";
assertThat(sources, containsString(expectedOne));
final String expectedTwo = " public byte sourceTwo()\n" + " {\n" + " return (byte)68;\n" + " }";
assertThat(sources, containsString(expectedTwo));
final String expectedThree = " public String sourceThree()\n" + " {\n" + " return \"EF\";\n" + " }";
assertThat(sources, containsString(expectedThree));
final String expectedFour = " public String sourceFour()\n" + " {\n" + " return \"GH\";\n" + " }";
assertThat(sources, containsString(expectedFour));
}
use of uk.co.real_logic.sbe.ir.Ir in project simple-binary-encoding by real-logic.
the class TargetCodeGeneratorTest method shouldLoadAndInstatiateNonStandardTargetLanguage.
@Test
public void shouldLoadAndInstatiateNonStandardTargetLanguage() throws Exception {
final Ir ir = mock(Ir.class);
final String outputDir = ".";
SbeTool.generate(ir, outputDir, "uk.co.real_logic.sbe.TestTargetLanguage");
verify(TestTargetLanguage.SINGLETON).generate();
assertThat(ir, is(TestTargetLanguage.ir));
assertThat(outputDir, is(TestTargetLanguage.outputDir));
}
use of uk.co.real_logic.sbe.ir.Ir in project simple-binary-encoding by real-logic.
the class CompositeElementsGenerationTest method shouldOtfDecodeCorrectly.
@Test
public void shouldOtfDecodeCorrectly() throws Exception {
final ByteBuffer encodedSchemaBuffer = ByteBuffer.allocate(SCHEMA_BUFFER_CAPACITY);
encodeSchema(encodedSchemaBuffer);
final ByteBuffer encodedMsgBuffer = ByteBuffer.allocate(MSG_BUFFER_CAPACITY);
encodeTestMessage(encodedMsgBuffer);
encodedSchemaBuffer.flip();
final Ir ir = decodeIr(encodedSchemaBuffer);
final DirectBuffer decodeBuffer = new UnsafeBuffer(encodedMsgBuffer);
final OtfHeaderDecoder otfHeaderDecoder = new OtfHeaderDecoder(ir.headerStructure());
assertThat(otfHeaderDecoder.getBlockLength(decodeBuffer, 0), is(22));
assertThat(otfHeaderDecoder.getSchemaId(decodeBuffer, 0), is(3));
assertThat(otfHeaderDecoder.getTemplateId(decodeBuffer, 0), is(1));
assertThat(otfHeaderDecoder.getSchemaVersion(decodeBuffer, 0), is(0));
final TokenListener mockTokenListener = mock(TokenListener.class);
OtfMessageDecoder.decode(decodeBuffer, otfHeaderDecoder.encodedLength(), MSG_ENCODER.sbeSchemaVersion(), MSG_ENCODER.sbeBlockLength(), ir.getMessage(MSG_ENCODER.sbeTemplateId()), mockTokenListener);
final InOrder inOrder = inOrder(mockTokenListener);
inOrder.verify(mockTokenListener).onBeginComposite(any(), any(), eq(2), eq(17));
inOrder.verify(mockTokenListener).onEnum(any(), eq(decodeBuffer), eq(8), any(), eq(3), eq(6), eq(0));
inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(9), any(), eq(0));
inOrder.verify(mockTokenListener).onBitSet(any(), eq(decodeBuffer), eq(10), any(), eq(8), eq(12), eq(0));
inOrder.verify(mockTokenListener).onBeginComposite(any(), any(), eq(13), eq(16));
inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(14), any(), eq(0));
inOrder.verify(mockTokenListener).onEncoding(any(), eq(decodeBuffer), eq(22), any(), eq(0));
inOrder.verify(mockTokenListener).onEndComposite(any(), any(), eq(13), eq(16));
inOrder.verify(mockTokenListener).onEndComposite(any(), any(), eq(2), eq(17));
}
use of uk.co.real_logic.sbe.ir.Ir 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());
}
use of uk.co.real_logic.sbe.ir.Ir 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();
}
}
}
}
Aggregations