public void serializeMessageMetadata(ByteBuf outputBuf) {
    switch (version) {
      case MESSAGE_METADATA_VERSION_V1:
        outputBuf.writeShort(version);
        if (encryptionKey != null) {
          outputBuf.writeInt(encryptionKey.remaining());
          outputBuf.writeBytes(encryptionKey);
        } else {
          outputBuf.writeInt(0);
        }
        break;
      default:
        throw new IllegalStateException("Unknown MessageMetadata version");
    }
  }
Serialize the MessageMetadata into the given {@link ByteBuf}
@param outputBuf the {@link ByteBuf} to which to write the serialized bytes into.
ambry-messageformat/src/main/java/com/github/ambry/messageformat/MessageMetadata.java