Search in sources :

Example 1 with DataStreamReplyHeaderProto

use of org.apache.ratis.proto.RaftProtos.DataStreamReplyHeaderProto in project incubator-ratis by apache.

the class NettyDataStreamUtils method decodeDataStreamReplyHeader.

static DataStreamReplyHeader decodeDataStreamReplyHeader(ByteBuf buf) {
    if (DataStreamPacketHeader.getSizeOfHeaderLen() > buf.readableBytes()) {
        return null;
    }
    int headerBufLen = buf.readInt();
    if (headerBufLen > buf.readableBytes()) {
        buf.resetReaderIndex();
        return null;
    }
    try {
        ByteBuf headerBuf = buf.slice(buf.readerIndex(), headerBufLen);
        DataStreamReplyHeaderProto header = DataStreamReplyHeaderProto.parseFrom(headerBuf.nioBuffer());
        final DataStreamPacketHeaderProto h = header.getPacketHeader();
        if (header.getPacketHeader().getDataLength() + headerBufLen <= buf.readableBytes()) {
            buf.readerIndex(buf.readerIndex() + headerBufLen);
            return new DataStreamReplyHeader(ClientId.valueOf(h.getClientId()), h.getType(), h.getStreamId(), h.getStreamOffset(), h.getDataLength(), header.getBytesWritten(), header.getSuccess(), header.getCommitInfosList());
        } else {
            buf.resetReaderIndex();
            return null;
        }
    } catch (InvalidProtocolBufferException e) {
        LOG.error("Fail to decode reply header:", e);
        buf.resetReaderIndex();
        return null;
    }
}
Also used : DataStreamReplyHeader(org.apache.ratis.protocol.DataStreamReplyHeader) DataStreamPacketHeaderProto(org.apache.ratis.proto.RaftProtos.DataStreamPacketHeaderProto) InvalidProtocolBufferException(org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException) DataStreamReplyHeaderProto(org.apache.ratis.proto.RaftProtos.DataStreamReplyHeaderProto) DataStreamRequestByteBuf(org.apache.ratis.netty.server.DataStreamRequestByteBuf) ByteBuf(org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf)

Aggregations

DataStreamRequestByteBuf (org.apache.ratis.netty.server.DataStreamRequestByteBuf)1 DataStreamPacketHeaderProto (org.apache.ratis.proto.RaftProtos.DataStreamPacketHeaderProto)1 DataStreamReplyHeaderProto (org.apache.ratis.proto.RaftProtos.DataStreamReplyHeaderProto)1 DataStreamReplyHeader (org.apache.ratis.protocol.DataStreamReplyHeader)1 InvalidProtocolBufferException (org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException)1 ByteBuf (org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf)1