use of com.yahoo.pulsar.common.util.protobuf.ByteBufCodedOutputStream in project pulsar by yahoo.
the class ManagedLedgerTest method getMessageWithMetadata.
public ByteBuf getMessageWithMetadata(byte[] data) throws IOException {
MessageMetadata messageData = MessageMetadata.newBuilder().setPublishTime(System.currentTimeMillis()).setProducerName("prod-name").setSequenceId(0).build();
ByteBuf payload = Unpooled.wrappedBuffer(data, 0, data.length);
int msgMetadataSize = messageData.getSerializedSize();
int headersSize = 4 + msgMetadataSize;
ByteBuf headers = PooledByteBufAllocator.DEFAULT.buffer(headersSize, headersSize);
ByteBufCodedOutputStream outStream = ByteBufCodedOutputStream.get(headers);
headers.writeInt(msgMetadataSize);
messageData.writeTo(outStream);
outStream.recycle();
return DoubleByteBuf.get(headers, payload);
}
use of com.yahoo.pulsar.common.util.protobuf.ByteBufCodedOutputStream in project pulsar by yahoo.
the class Commands method serializeCommandMessageWithSize.
private static ByteBuf serializeCommandMessageWithSize(BaseCommand cmd, ByteBuf metadataAndPayload) {
// / Wire format
// [TOTAL_SIZE] [CMD_SIZE][CMD] [METADATA_SIZE][METADATA] [PAYLOAD]
int cmdSize = cmd.getSerializedSize();
int totalSize = 4 + cmdSize + metadataAndPayload.readableBytes();
int headersSize = 4 + 4 + cmdSize;
ByteBuf headers = PooledByteBufAllocator.DEFAULT.buffer(headersSize);
// External frame
headers.writeInt(totalSize);
try {
// Write cmd
headers.writeInt(cmdSize);
ByteBufCodedOutputStream outStream = ByteBufCodedOutputStream.get(headers);
cmd.writeTo(outStream);
outStream.recycle();
} catch (IOException e) {
// This is in-memory serialization, should not fail
throw new RuntimeException(e);
}
return DoubleByteBuf.get(headers, metadataAndPayload);
}
use of com.yahoo.pulsar.common.util.protobuf.ByteBufCodedOutputStream in project pulsar by yahoo.
the class CommandsTest method computeChecksum.
private int computeChecksum(MessageMetadata msgMetadata, ByteBuf compressedPayload) throws IOException {
int metadataSize = msgMetadata.getSerializedSize();
int metadataFrameSize = 4 + metadataSize;
ByteBuf metaPayloadFrame = PooledByteBufAllocator.DEFAULT.buffer(metadataFrameSize, metadataFrameSize);
ByteBufCodedOutputStream outStream = ByteBufCodedOutputStream.get(metaPayloadFrame);
metaPayloadFrame.writeInt(metadataSize);
msgMetadata.writeTo(outStream);
ByteBuf payload = compressedPayload.copy();
ByteBuf metaPayloadBuf = DoubleByteBuf.get(metaPayloadFrame, payload);
int computedChecksum = Crc32cChecksum.computeChecksum(metaPayloadBuf);
outStream.recycle();
metaPayloadBuf.release();
return computedChecksum;
}
Aggregations