public static int encodeString(PositionedByteRange dst, String val, Order ord) {
    if (null == val) {
      return encodeNull(dst, ord);
    }
    if (val.contains("\u0000"))
      throw new IllegalArgumentException("Cannot encode String values containing '\\u0000'");
    final int offset = dst.getOffset(), start = dst.getPosition();
    dst.put(TEXT);
    // TODO: is there no way to decode into dst directly?
    dst.put(val.getBytes(UTF8));
    dst.put(TERM);
    ord.apply(dst.getBytes(), offset + start, dst.getPosition() - start);
    return dst.getPosition() - start;
  }
Encode a String value. String encoding is 0x00-terminated and so it does not support
{@code \u0000} codepoints in the value.
@param dst The destination to which the encoded value is written.
@param val The value to encode.
@param ord The {@link Order} to respect while encoding {@code val}.
@return the number of bytes written.
@throws IllegalArgumentException when {@code val} contains a {@code \u0000}.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java