@Override
  public long writeTo(WritableByteChannel channel) throws IOException {
    if (byteBufferToSend == null) {
      prepareBuffer();
      byteBufferToSend = bufferToSend.nioBuffer();
    }
    return byteBufferToSend.hasRemaining() ? channel.write(byteBufferToSend) : 0;
  }
Request Response for serialization and de-serialization
ambry-protocol/src/main/java/com/github/ambry/protocol/RequestOrResponse.java