private ByteBuffer serializeBlobPropertiesInVersion(BlobProperties blobProperties) {
    ByteBuffer outputBuffer = null;
    switch (version) {
      case BlobPropertiesSerDe.VERSION_1:
        int size = Version_Field_Size_In_Bytes + Long.BYTES + Byte.BYTES + Long.BYTES + Long.BYTES + Integer.BYTES
            + Utils.getNullableStringLength(blobProperties.getContentType()) + Integer.BYTES
            + Utils.getNullableStringLength(blobProperties.getOwnerId()) + Integer.BYTES
            + Utils.getNullableStringLength(blobProperties.getServiceId());
        outputBuffer = ByteBuffer.allocate(size);
        outputBuffer.putShort(VERSION_1);
        outputBuffer.putLong(blobProperties.getTimeToLiveInSeconds());
        outputBuffer.put(blobProperties.isPrivate() ? (byte) 1 : (byte) 0);
        outputBuffer.putLong(blobProperties.getCreationTimeInMs());
        outputBuffer.putLong(blobProperties.getBlobSize());
        Utils.serializeNullableString(outputBuffer, blobProperties.getContentType());
        Utils.serializeNullableString(outputBuffer, blobProperties.getOwnerId());
        Utils.serializeNullableString(outputBuffer, blobProperties.getServiceId());
        outputBuffer.flip();
        break;
      case BlobPropertiesSerDe.VERSION_2:
        size = Version_Field_Size_In_Bytes + Long.BYTES + Byte.BYTES + Long.BYTES + Long.BYTES + Integer.BYTES
            + Utils.getNullableStringLength(blobProperties.getContentType()) + Integer.BYTES
            + Utils.getNullableStringLength(blobProperties.getOwnerId()) + Integer.BYTES
            + Utils.getNullableStringLength(blobProperties.getServiceId()) + Short.BYTES + Short.BYTES;
        outputBuffer = ByteBuffer.allocate(size);
        outputBuffer.putShort(VERSION_2);
        outputBuffer.putLong(blobProperties.getTimeToLiveInSeconds());
        outputBuffer.put(blobProperties.isPrivate() ? (byte) 1 : (byte) 0);
        outputBuffer.putLong(blobProperties.getCreationTimeInMs());
        outputBuffer.putLong(blobProperties.getBlobSize());
        Utils.serializeNullableString(outputBuffer, blobProperties.getContentType());
        Utils.serializeNullableString(outputBuffer, blobProperties.getOwnerId());
        Utils.serializeNullableString(outputBuffer, blobProperties.getServiceId());
        outputBuffer.putShort(blobProperties.getAccountId());
        outputBuffer.putShort(blobProperties.getContainerId());
        outputBuffer.flip();
        break;
      case BlobPropertiesSerDe.VERSION_3:
        size = VERSION_FIELD_SIZE_IN_BYTES + TTL_FIELD_SIZE_IN_BYTES + PRIVATE_FIELD_SIZE_IN_BYTES
            + CREATION_TIME_FIELD_SIZE_IN_BYTES + BLOB_SIZE_FIELD_SIZE_IN_BYTES + Utils.getIntStringLength(
            blobProperties.getContentType()) + Utils.getIntStringLength(blobProperties.getOwnerId())
            + Utils.getIntStringLength(blobProperties.getServiceId()) + Short.BYTES + Short.BYTES
            + ENCRYPTED_FIELD_SIZE_IN_BYTES;
        outputBuffer = ByteBuffer.allocate(size);
        outputBuffer.putShort(VERSION_3);
        outputBuffer.putLong(blobProperties.getTimeToLiveInSeconds());
        outputBuffer.put(blobProperties.isPrivate() ? (byte) 1 : (byte) 0);
        outputBuffer.putLong(blobProperties.getCreationTimeInMs());
        outputBuffer.putLong(blobProperties.getBlobSize());
        Utils.serializeNullableString(outputBuffer, blobProperties.getContentType());
        Utils.serializeNullableString(outputBuffer, blobProperties.getOwnerId());
        Utils.serializeNullableString(outputBuffer, blobProperties.getServiceId());
        outputBuffer.putShort(blobProperties.getAccountId());
        outputBuffer.putShort(blobProperties.getContainerId());
        outputBuffer.put(blobProperties.isEncrypted() ? (byte) 1 : (byte) 0);
        outputBuffer.flip();
        break;
      case BlobPropertiesSerDe.VERSION_4:
      case BlobPropertiesSerDe.VERSION_5:
        BlobPropertiesSerDe.CURRENT_VERSION = version;
        outputBuffer = ByteBuffer.allocate(BlobPropertiesSerDe.getBlobPropertiesSerDeSize(blobProperties));
        BlobPropertiesSerDe.serializeBlobProperties(outputBuffer, blobProperties);
        outputBuffer.flip();
        break;
    }
    return outputBuffer;
  }
Serialize {@link BlobProperties} using {@link BlobPropertiesSerDe} in the given version
@param blobProperties {@link BlobProperties} that needs to be serialized
@return the {@link ByteBuffer} containing the serialized {@link BlobPropertiesSerDe}
ambry-messageformat/src/test/java/com/github/ambry/messageformat/BlobPropertiesTest.java