@Override
  protected void prepareBuffer() {
    bufferToSend = PooledByteBufAllocator.DEFAULT.ioBuffer(
        (int) super.sizeInBytes() + (Partition_Response_Info_List_Size + partitionResponseInfoSize));
    writeHeader();
    if (partitionResponseInfoList != null) {
      bufferToSend.writeInt(partitionResponseInfoList.size());
      for (PartitionResponseInfo partitionResponseInfo : partitionResponseInfoList) {
        partitionResponseInfo.writeTo(bufferToSend);
      }
    }
    if (toSend != null) {
      ByteBuf toSendContent = toSend.content();
      if (toSendContent != null) {
        // Since this composite blob will be a readonly blob, we don't really care about if it's allocated
        // on a direct memory or not.
        CompositeByteBuf compositeByteBuf = bufferToSend.alloc().compositeDirectBuffer();
        int maxNumComponent = 1 + toSendContent.nioBufferCount();
        compositeByteBuf.addComponent(true, bufferToSend);
        compositeByteBuf.addComponent(true, toSendContent);
        bufferToSend = compositeByteBuf;
        sendSizeInBufferToSend = toSendContent.readableBytes();
        toSend = null;
      }
    }
  }
A private method shared by {@link GetResponse#writeTo(WritableByteChannel)} and
{@link GetResponse#writeTo(AsyncWritableChannel, Callback)}.
This method allocate bufferToSend and write metadata to it if bufferToSend is null.
ambry-protocol/src/main/java/com/github/ambry/protocol/GetResponse.java