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;
}
}
Aggregations