Search in sources :

Example 6 with DirectBufferInputStream

use of org.agrona.io.DirectBufferInputStream in project zeebe by zeebe-io.

the class BufferingServerOutput method getAsControlMessageData.

public Map<String, Object> getAsControlMessageData(int index) {
    final ControlMessageResponseDecoder decoder = getAs(index, new ControlMessageResponseDecoder());
    final UnsafeBuffer dataBuf = new UnsafeBuffer(new byte[decoder.dataLength()]);
    decoder.getData(dataBuf, 0, dataBuf.capacity());
    return msgPackDecoder.readMsgPack(new DirectBufferInputStream(dataBuf));
}
Also used : DirectBufferInputStream(org.agrona.io.DirectBufferInputStream) ControlMessageResponseDecoder(io.zeebe.protocol.clientapi.ControlMessageResponseDecoder) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 7 with DirectBufferInputStream

use of org.agrona.io.DirectBufferInputStream in project zeebe by zeebe-io.

the class ExecuteCommandResponse method wrap.

@Override
public void wrap(DirectBuffer responseBuffer, int offset, int length) {
    messageHeaderDecoder.wrap(responseBuffer, offset);
    if (messageHeaderDecoder.templateId() != responseDecoder.sbeTemplateId()) {
        if (messageHeaderDecoder.templateId() == ErrorResponseDecoder.TEMPLATE_ID) {
            errorResponse.wrap(responseBuffer, offset + messageHeaderDecoder.encodedLength(), length);
            throw new RuntimeException("Unexpected error response from broker: " + errorResponse.getErrorCode() + " - " + errorResponse.getErrorData());
        } else {
            throw new RuntimeException("Unexpected response from broker. Template id " + messageHeaderDecoder.templateId());
        }
    }
    responseDecoder.wrap(responseBuffer, offset + messageHeaderDecoder.encodedLength(), messageHeaderDecoder.blockLength(), messageHeaderDecoder.version());
    final int eventLength = responseDecoder.eventLength();
    final int eventOffset = responseDecoder.limit() + eventHeaderLength();
    try (InputStream is = new DirectBufferInputStream(responseBuffer, eventOffset, eventLength)) {
        event = msgPackHelper.readMsgPack(is);
    } catch (IOException e) {
        LangUtil.rethrowUnchecked(e);
    }
}
Also used : DirectBufferInputStream(org.agrona.io.DirectBufferInputStream) DirectBufferInputStream(org.agrona.io.DirectBufferInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

DirectBufferInputStream (org.agrona.io.DirectBufferInputStream)7 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PartitionsResponse (io.zeebe.broker.system.log.PartitionsResponse)1 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)1 ClientException (io.zeebe.client.cmd.ClientException)1 EventImpl (io.zeebe.client.event.impl.EventImpl)1 ControlMessageResponseDecoder (io.zeebe.protocol.clientapi.ControlMessageResponseDecoder)1 Test (org.junit.Test)1 MessagePackFactory (org.msgpack.jackson.dataformat.MessagePackFactory)1