void writeTextBytes(byte[] bytes, int start, int length) throws TException {
    writeRawBytes(nonNullByte, 0, 1);
    int begin = 0;
    int i = start;
    for (; i < length; i++) {
      if (bytes[i] == 0 || bytes[i] == 1) {
        // Write the first part of the array
        if (i > begin) {
          writeRawBytes(bytes, begin, i - begin);
        }
        // Write the escaped byte.
        if (bytes[i] == 0) {
          writeRawBytes(escapedNull, 0, escapedNull.length);
        } else {
          writeRawBytes(escapedOne, 0, escapedOne.length);
        }
        // Move the pointer to the next byte, since we have written
        // out the escaped byte in the block above already.
        begin = i + 1;
      }
    }
    // Write the remaining part of the array
    if (i > begin) {
      writeRawBytes(bytes, begin, i - begin);
    }
    // Write the terminating NULL byte
    writeRawBytes(nullByte, 0, 1);
  }
This method always return the same instance of TSet to avoid creating new
instances. It is the responsibility of the caller to read the value before
calling this method again.
serde/src/java/org/apache/hadoop/hive/serde2/thrift/TBinarySortableProtocol.java