Search in sources :

Example 1 with BoltResponseMessageReader

use of org.neo4j.bolt.v1.messaging.BoltResponseMessageReader in project neo4j by neo4j.

the class MessageMatchers method responseMessage.

public static ResponseMessage responseMessage(byte[] bytes) throws IOException {
    BoltResponseMessageReader unpacker = responseReader(bytes);
    BoltResponseMessageRecorder consumer = new BoltResponseMessageRecorder();
    try {
        if (unpacker.hasNext()) {
            unpacker.read(consumer);
            return consumer.asList().get(0);
        }
        throw new IllegalArgumentException("Expected a message in `" + HexPrinter.hex(bytes) + "`");
    } catch (Throwable e) {
        throw new IOException("Failed to deserialize response, '" + e.getMessage() + "'.\n" + "Raw data: \n" + HexPrinter.hex(bytes), e);
    }
}
Also used : BoltResponseMessageRecorder(org.neo4j.bolt.v1.messaging.BoltResponseMessageRecorder) BoltResponseMessageReader(org.neo4j.bolt.v1.messaging.BoltResponseMessageReader) IOException(java.io.IOException)

Example 2 with BoltResponseMessageReader

use of org.neo4j.bolt.v1.messaging.BoltResponseMessageReader in project neo4j by neo4j.

the class BoltResponseMessageTest method serializeAndDeserialize.

private <T extends ResponseMessage> T serializeAndDeserialize(T msg) throws IOException {
    RecordingByteChannel channel = new RecordingByteChannel();
    BoltResponseMessageReader reader = new BoltResponseMessageReader(new Neo4jPack.Unpacker(new BufferedChannelInput(16).reset(channel)));
    BoltResponseMessageWriter writer = new BoltResponseMessageWriter(new Neo4jPack.Packer(new BufferedChannelOutput(channel)), NO_BOUNDARY_HOOK);
    msg.dispatch(writer);
    writer.flush();
    channel.eof();
    return unpack(reader, channel);
}
Also used : BufferedChannelInput(org.neo4j.bolt.v1.packstream.BufferedChannelInput) BufferedChannelOutput(org.neo4j.bolt.v1.packstream.BufferedChannelOutput)

Aggregations

IOException (java.io.IOException)1 BoltResponseMessageReader (org.neo4j.bolt.v1.messaging.BoltResponseMessageReader)1 BoltResponseMessageRecorder (org.neo4j.bolt.v1.messaging.BoltResponseMessageRecorder)1 BufferedChannelInput (org.neo4j.bolt.v1.packstream.BufferedChannelInput)1 BufferedChannelOutput (org.neo4j.bolt.v1.packstream.BufferedChannelOutput)1