Search in sources :

Example 26 with IrGenerator

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

the class EncodedIrTest method shouldDecodeCorrectMessages.

@Test
public void shouldDecodeCorrectMessages() throws Exception {
    final MessageSchema schema = parse(TestUtil.getLocalResource("code-generation-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final ByteBuffer buffer = ByteBuffer.allocateDirect(CAPACITY);
    final IrEncoder irEncoder = new IrEncoder(buffer, ir);
    irEncoder.encode();
    buffer.flip();
    final IrDecoder irDecoder = new IrDecoder(buffer);
    final Ir decodedIr = irDecoder.decode();
    assertThat(decodedIr.messages().size(), is(ir.messages().size()));
    for (final List<Token> decodedTokenList : decodedIr.messages()) {
        final List<Token> tokens = ir.getMessage(decodedTokenList.get(0).id());
        assertThat(decodedTokenList.size(), is(tokens.size()));
        for (int i = 0, size = decodedTokenList.size(); i < size; i++) {
            assertEqual(decodedTokenList.get(i), tokens.get(i));
        }
    }
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 27 with IrGenerator

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

the class EncodedIrTest method shouldEncodeIr.

@Test
public void shouldEncodeIr() throws Exception {
    final MessageSchema schema = parse(TestUtil.getLocalResource("basic-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final ByteBuffer buffer = ByteBuffer.allocateDirect(CAPACITY);
    final IrEncoder irEncoder = new IrEncoder(buffer, ir);
    irEncoder.encode();
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 28 with IrGenerator

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

the class EncodedIrTest method shouldHandleRightSizedBuffer.

@Test
public void shouldHandleRightSizedBuffer() throws Exception {
    final MessageSchema schema = parse(TestUtil.getLocalResource("basic-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final ByteBuffer buffer = ByteBuffer.allocateDirect(CAPACITY);
    final IrEncoder irEncoder = new IrEncoder(buffer, ir);
    irEncoder.encode();
    buffer.flip();
    final ByteBuffer readBuffer = ByteBuffer.allocateDirect(buffer.remaining());
    readBuffer.put(buffer);
    readBuffer.flip();
    final IrDecoder irDecoder = new IrDecoder(readBuffer);
    irDecoder.decode();
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 29 with IrGenerator

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

the class EncodedIrTest method shouldDecodeCorrectFrame.

@Test
public void shouldDecodeCorrectFrame() throws Exception {
    final MessageSchema schema = parse(TestUtil.getLocalResource("code-generation-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final ByteBuffer buffer = ByteBuffer.allocateDirect(CAPACITY);
    final IrEncoder irEncoder = new IrEncoder(buffer, ir);
    irEncoder.encode();
    buffer.flip();
    final IrDecoder irDecoder = new IrDecoder(buffer);
    final Ir decodedIr = irDecoder.decode();
    assertThat(decodedIr.id(), is(ir.id()));
    assertThat(decodedIr.version(), is(ir.version()));
    assertThat(decodedIr.semanticVersion(), is(ir.semanticVersion()));
    assertThat(decodedIr.packageName(), is(ir.packageName()));
    assertThat(decodedIr.namespaceName(), is(ir.namespaceName()));
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 30 with IrGenerator

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

the class EncodedIrTest method shouldEncodeThenDecodeIr.

@Test
public void shouldEncodeThenDecodeIr() throws Exception {
    final MessageSchema schema = parse(TestUtil.getLocalResource("basic-schema.xml"), ParserOptions.DEFAULT);
    final IrGenerator irg = new IrGenerator();
    final Ir ir = irg.generate(schema);
    final ByteBuffer buffer = ByteBuffer.allocateDirect(CAPACITY);
    final IrEncoder irEncoder = new IrEncoder(buffer, ir);
    irEncoder.encode();
    buffer.flip();
    final IrDecoder decoder = new IrDecoder(buffer);
    decoder.decode();
}
Also used : IrGenerator(uk.co.real_logic.sbe.xml.IrGenerator) MessageSchema(uk.co.real_logic.sbe.xml.MessageSchema) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

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