void serializeMessageInfoAndMetadataList(ByteBuf outputBuf) {
    if (version >= VERSION_5) {
      outputBuf.writeShort(version);
    }
    outputBuf.writeInt(messageInfoList == null ? 0 : messageInfoList.size());
    if (messageInfoList != null) {
      ListIterator<MessageInfo> infoListIterator = messageInfoList.listIterator();
      ListIterator<MessageMetadata> metadataListIterator = messageMetadataList.listIterator();
      while (infoListIterator.hasNext()) {
        MessageInfo messageInfo = infoListIterator.next();
        MessageMetadata messageMetadata = metadataListIterator.next();
        outputBuf.writeBytes(messageInfo.getStoreKey().toBytes());
        outputBuf.writeLong(messageInfo.getSize());
        outputBuf.writeLong(messageInfo.getExpirationTimeInMs());
        outputBuf.writeByte(messageInfo.isDeleted() ? UPDATED : (byte) ~UPDATED);
        if (version < VERSION_1 || version > VERSION_MAX) {
          throw new IllegalArgumentException("Unknown version in MessageInfoList " + version);
        }
        if (version >= VERSION_5) {
          outputBuf.writeByte(messageInfo.isTtlUpdated() ? UPDATED : (byte) ~UPDATED);
        }
        if (version >= VERSION_6) {
          outputBuf.writeByte(messageInfo.isUndeleted() ? UPDATED : (byte) ~UPDATED);
        }
        if (version > VERSION_1) {
          Long crc = messageInfo.getCrc();
          if (crc != null) {
            outputBuf.writeByte(FIELD_PRESENT);
            outputBuf.writeLong(crc);
          } else {
            outputBuf.writeByte((byte) ~FIELD_PRESENT);
          }
        }
        if (version > VERSION_2) {
          outputBuf.writeShort(messageInfo.getAccountId());
          outputBuf.writeShort(messageInfo.getContainerId());
          outputBuf.writeLong(messageInfo.getOperationTimeMs());
        }
        if (version >= VERSION_6) {
          outputBuf.writeShort(messageInfo.getLifeVersion());
        }
        if (version > VERSION_3) {
          if (messageMetadata != null) {
            outputBuf.writeByte(FIELD_PRESENT);
            messageMetadata.serializeMessageMetadata(outputBuf);
          } else {
            outputBuf.writeByte((byte) ~FIELD_PRESENT);
          }
        }
      }
    }
  }
Serialize this object into the given buffer.
@param outputBuf the {@link ByteBuf} to serialize into.
ambry-protocol/src/main/java/com/github/ambry/protocol/MessageInfoAndMetadataListSerde.java