public static int encodeBlobCopy(PositionedByteRange dst, byte[] val, int voff, int vlen,
    Order ord) {
    if (null == val) {
      encodeNull(dst, ord);
      if (ASCENDING == ord) return 1;
      else {
        // DESCENDING ordered BlobCopy requires a termination bit to preserve
        // sort-order semantics of null values.
        dst.put(ord.apply(TERM));
        return 2;
      }
    }
    // Blobs as final entry in a compound key are written unencoded.
    assert dst.getRemaining() >= vlen + (ASCENDING == ord ? 1 : 2);
    if (DESCENDING == ord) {
      for (int i = 0; i < vlen; i++) {
        if (TERM == val[voff + i]) {
          throw new IllegalArgumentException("0x00 bytes not permitted in value.");
        }
      }
    }
    final int offset = dst.getOffset(), start = dst.getPosition();
    dst.put(BLOB_COPY);
    dst.put(val, voff, vlen);
    // DESCENDING ordered BlobCopy requires a termination bit to preserve
    // sort-order semantics of null values.
    if (DESCENDING == ord) dst.put(TERM);
    ord.apply(dst.getBytes(), offset + start, dst.getPosition() - start);
    return dst.getPosition() - start;
  }
Encode a Blob value as a byte-for-byte copy. BlobCopy encoding in DESCENDING order is NULL
terminated so as to preserve proper sorting of {@code []} and so it does not support
{@code 0x00} in the value.
@return the number of bytes written.
@throws IllegalArgumentException when {@code ord} is DESCENDING and {@code val} contains a
                                 {@code 0x00} byte.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java