use of com.yahoo.pulsar.common.api.Commands.RecyclableHeapByteBuf in project pulsar by yahoo.
the class ByteBufCodedInputStream method readBytes.
/** Read a {@code bytes} field value from the stream. */
public ByteString readBytes() throws IOException {
final int size = readRawVarint32();
if (size == 0) {
return ByteString.EMPTY;
} else {
RecyclableHeapByteBuf heapBuf = RecyclableHeapByteBuf.get();
if (size > heapBuf.writableBytes()) {
heapBuf.capacity(size);
}
heapBuf.writeBytes(buf, size);
ByteString res = ByteString.copyFrom(heapBuf.array(), heapBuf.arrayOffset(), heapBuf.readableBytes());
heapBuf.recycle();
return res;
}
}
use of com.yahoo.pulsar.common.api.Commands.RecyclableHeapByteBuf in project pulsar by yahoo.
the class ByteBufCodedOutputStream method writeRawBytes.
/** Write a byte string. */
public void writeRawBytes(final ByteString value) throws IOException {
RecyclableHeapByteBuf heapBuf = RecyclableHeapByteBuf.get();
if (value.size() > heapBuf.writableBytes()) {
heapBuf.capacity(value.size());
}
value.copyTo(heapBuf.array(), 0);
heapBuf.writerIndex(value.size());
buf.writeBytes(heapBuf);
heapBuf.recycle();
}
Aggregations