read encoding len.
see StringPool.cpp ENCODE_LENGTH
430766
private static int readLen(ByteBuffer buffer) {
        int len = 0;
        int i = Buffers.readUByte(buffer);
        if ((i & 0x80) != 0) {
            //read one more byte.
            len |= (i & 0x7f) << 8;
            len += Buffers.readUByte(buffer);
        } else {
            len = i;
        }
        return len;
    }
955176
def decodeLength(length):
        
        bytes_length = len(length)

        if bytes_length < 2:
            offset = b'\x00\x00\x00'
            XOR = 0
        elif bytes_length < 3:
            offset = b'\x00\x00'
            XOR = 0x8000
        elif bytes_length < 4:
            offset = b'\x00'
            XOR = 0xC00000
        elif bytes_length < 5:
            offset = b''
            XOR = 0xE0000000
        else:
            raise ConnectionError('Unable to decode length of {}'.format(length))

        decoded = unpack('!I', (offset + length))[0]
        decoded ^= XOR
        return decoded
278707
private int extractNextTlvElementLength(IoBuffer in) {
        if (!hasRemainingData(in, 2)) {
            return NOT_ENOUGH_DATA;
        }
        try {
            in.mark();
            int firstByte = in.getUnsigned();
            boolean tlv8 = (firstByte & TLV16_MASK) == 0;
            if (tlv8) {
                // 8 bit length. NB! Reads one unsigned byte as an integer
                return in.getUnsigned() + TLV8_HEADER_LENGTH;
            }
            // skip tlv16 LSB byte
            in.skip(1);
            if (!hasRemainingData(in, 2)) {
                return NOT_ENOUGH_DATA;
            }
            // 16 bit length. NB! Reads two bytes unsigned integer
            return in.getUnsignedShort() + TLV16_HEADER_LENGTH;
        } finally {
            in.reset();
        }
    }
693999
def readBuffer(self, newLength):
        
        result = Buffer(self.buf, self.offset, newLength)
        self.skip(newLength)
        return result
650455
def length_prefix(length, offset):
    
    if length < 56:
        return chr(offset + length)
    else:
        length_string = int_to_big_endian(length)
        return chr(offset + 56 - 1 + len(length_string)) + length_string
12745
def get_byte_length(self, decoded=True) -> int:
        
        end = len(self.decoded_bits) if decoded else len(self.__plain_bits)
        end = self.convert_index(end, 0, 2, decoded=decoded)[0]
        return int(end)
653421
def ReadString(self):
        
        length = self.ReadUInt8()
        return self.unpack(str(length) + 's', length)
213457
def ansi_len(string):
    """"""
    return len(string) - wcswidth(re.compile(r'\x1b[^m]*m').sub('', string))
380479
def create_string_buffer(init, size=None, encoding=sys.getdefaultencoding()):
    
    if isinstance(init, six.string_types + (six.binary_type,)):
        if size is None:
            size = len(init) + 1
        buftype = c_char * size
        buf = buftype()
        try:
            buf.value = init.encode(encoding)
        except AttributeError:
            buf.value = init

        return buf
    elif isinstance(init, six.integer_types):
        buftype = c_char * init
        buf = buftype()
        return buf
    raise TypeError(init)
50787
public String readStringLengthEncoded(final Charset charset) {
    int length = (int) getLengthEncodedNumeric();
    String string = new String(buf, position, length, charset);
    position += length;
    return string;
  }
701517
private static int utf8Length(String string) {
    int stringLength = string.length();
    int utf8Length = 0;
    for (int i = 0; i < stringLength; i++) {
      int c = string.charAt(i);
      if (c <= 0x007F) {
        utf8Length++;
      } else if (c > 0x07FF) {
        utf8Length += 3;
      } else {
        utf8Length += 2;
      }
    }
    return utf8Length;
  }
1102040
def read(self, length=None):
        
        if not length is None:
            if not isinstance(length, inttype) :
                raise TypeError("length to read should be number")
            buf = create_string_buffer(length)
            readbytes = libcrypto.BIO_read(self.bio, buf, length)
            if readbytes == -2:
                raise NotImplementedError("Function is not supported by" +
                                          "this BIO")
            if readbytes == -1:
                raise IOError
            if readbytes == 0:
                return b""
            return buf.raw[:readbytes]
        else:
            buf = create_string_buffer(1024)
            out = b""
            readbytes = 1
            while readbytes > 0:
                readbytes = libcrypto.BIO_read(self.bio, buf, 1024)
                if readbytes == -2:
                    raise NotImplementedError("Function is not supported by " +
                                              "this BIO")
                if readbytes == -1:
                    raise IOError
                if readbytes > 0:
                    out += buf.raw[:readbytes]
            return out
1065095
def _readString(self, length_fmt="H"):
        
        (length,) = self._readStruct(">{0}".format(length_fmt))
        ba = self.object_stream.read(length)
        return to_unicode(ba)
488573
def to_s
      max_size = CF.CFStringGetMaximumSizeForEncoding(length, UTF8)
      range = CF::Range.new
      range[:location] = 0
      range[:length] = length
      buffer = FFI::MemoryPointer.new(:char, max_size)

      cfindex = CF.find_type(:cfindex)
      bytes_used_buffer = FFI::MemoryPointer.new(cfindex)

      CF.CFStringGetBytes(self, range, UTF8, 0, 0, buffer, max_size, bytes_used_buffer)

      bytes_used = if cfindex == CF.find_type(:long_long)
        bytes_used_buffer.read_long_long
      else
        bytes_used_buffer.read_long
      end

      if HAS_ENCODING
        buffer.read_string(bytes_used).force_encoding(Encoding::UTF_8)
      else
        buffer.read_string(bytes_used)
      end
    end
620288
private int readChunkLength()
    throws IOException
  {
    int length = 0;
    int ch;

    ReadStream is = _next;

    // skip whitespace
    for (ch = is.read();
         ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
         ch = is.read()) {
    }

    // XXX: This doesn't properly handle the case when when the browser
    // sends headers at the end of the data.  See the HTTP/1.1 spec.
    for (; ch > 0 && ch != '\r' && ch != '\n'; ch = is.read()) {
      if ('0' <= ch && ch <= '9')
        length = 16 * length + ch - '0';
      else if ('a' <= ch && ch <= 'f')
        length = 16 * length + ch - 'a' + 10;
      else if ('A' <= ch && ch <= 'F')
        length = 16 * length + ch - 'A' + 10;
      else if (ch == ' ' || ch == '\t') {
        //if (dbg.canWrite())
        //  dbg.println("unexpected chunk whitespace.");
      }
      else {
        StringBuilder sb = new StringBuilder();

        sb.append((char) ch);
        for (int ch1 = is.read();
             ch1 >= 0 && ch1 != '\r' && ch1 != '\n';
             ch1 = is.read()) {
          sb.append((char) ch1);
        }

        throw new IOException("HTTP/1.1 protocol error: bad chunk at"
                              + " '" + sb + "'"
                              + " 0x" + Integer.toHexString(ch)
                              + " length=" + length);
      }
    }

    if (ch == '\r')
      ch = is.read();

    return length;
  }
1186740
function wstring(bits, s) {
      var charLength = bits / 8;
      var dataLength = s.length * charLength;
      var res = Buffer.alloc(xutil.padded_length(dataLength));
      debugger;
      var write = res[bufferWriteBits[bits]];
      res.fill(0);
      for (var i = 0; i < s.length; i++) write.call(res, s.charCodeAt(i), i * charLength);
      return res;
    }
341329
function chunkLength (chunk, encoding) {
  if (!chunk) {
    return 0
  }

  return !Buffer.isBuffer(chunk)
    ? Buffer.byteLength(chunk, encoding)
    : chunk.length
}