@Override
  public byte[] toBytes() {
    ByteBuffer idBuf = ByteBuffer.allocate(sizeInBytes());
    idBuf.putShort(version);
    byte flag;
    switch (version) {
      case BLOB_ID_V1:
        break;
      case BLOB_ID_V2:
      case BLOB_ID_V3:
        flag = (byte) (type.ordinal() & BLOB_ID_TYPE_MASK);
        idBuf.put(flag);
        idBuf.put(datacenterId);
        idBuf.putShort(accountId);
        idBuf.putShort(containerId);
        break;
      case BLOB_ID_V4:
        flag = (byte) (type.ordinal() & BLOB_ID_TYPE_MASK);
        flag |= isEncrypted ? IS_ENCRYPTED_MASK : 0;
        idBuf.put(flag);
        idBuf.put(datacenterId);
        idBuf.putShort(accountId);
        idBuf.putShort(containerId);
        break;
      case BLOB_ID_V5:
      case BLOB_ID_V6:
        flag = (byte) (type.ordinal() & BLOB_ID_TYPE_MASK);
        flag |= isEncrypted ? IS_ENCRYPTED_MASK : 0;
        flag |= (blobDataType.ordinal() << BLOB_DATA_TYPE_SHIFT);
        idBuf.put(flag);
        idBuf.put(datacenterId);
        idBuf.putShort(accountId);
        idBuf.putShort(containerId);
        break;
      default:
        throw new IllegalArgumentException("blobId version=" + version + " not supported");
    }
    idBuf.put(partitionId.getBytes());
    switch (version) {
      case BLOB_ID_V6:
        UuidSerDe.serialize(uuid, idBuf);
        break;
      default:
        byte[] uuidBytes = getUuid().getBytes();
        idBuf.putInt(uuidBytes.length);
        idBuf.put(uuidBytes);
        break;
    }
    return idBuf.array();
  }
@return the uuid string associated with this BlobId
ambry-commons/src/main/java/com/github/ambry/commons/BlobId.java