code: def _decode_length(self, offset, sizeof_char):
          
          sizeof_2chars = sizeof_char << 1
          fmt = "<2{}".format('B' if sizeof_char == 1 else 'H')
          highbit = 0x80 << (8 * (sizeof_char - 1))
  
          length1, length2 = unpack(fmt, self.m_charbuff[offset:(offset + sizeof_2chars)])
  
          if (length1 & highbit) != 0:
              length = ((length1 & ~highbit) << (8 * sizeof_char)) | length2
              size = sizeof_2chars
          else:
              length = length1
              size = sizeof_char
  
          if sizeof_char == 1:
              assert length <= 0x7FFF, "length of UTF-8 string is too large! At offset={}".format(offset)
          else:
              assert length <= 0x7FFFFFFF, "length of UTF-16 string is too large!  At offset={}".format(offset)
  
          return length, size
docs: Generic Length Decoding at offset of string
  
          The method works for both 8 and 16 bit Strings.
          Length checks are enforced:
          * 8 bit strings: maximum of 0x7FFF bytes (See
          http://androidxref.com/9.0.0_r3/xref/frameworks/base/libs/androidfw/ResourceTypes.cpp#692)
          * 16 bit strings: maximum of 0x7FFFFFF bytes (See
          http://androidxref.com/9.0.0_r3/xref/frameworks/base/libs/androidfw/ResourceTypes.cpp#670)
  
          :param offset: offset into the string data section of the beginning of
          the string
          :param sizeof_char: number of bytes per char (1 = 8bit, 2 = 16bit)
          :returns: tuple of (length, read bytes)