protected void writeHeader() {
    if (bufferToSend == null) {
      throw new IllegalStateException("Buffer to send should not be null");
    }
    bufferToSend.writeLong(sizeInBytes());
    bufferToSend.writeShort((short) type.ordinal());
    bufferToSend.writeShort(versionId);
    bufferToSend.writeInt(correlationId);
    Utils.serializeString(bufferToSend, clientId, Charset.defaultCharset());
  }
Request Response for serialization and de-serialization
ambry-protocol/src/main/java/com/github/ambry/protocol/RequestOrResponse.java