def _parse(self, stream, context, path): b = byte2int(_read_stream(stream, 1)) if b & 0x80 == 0: num = b elif b & 0xc0 == 0x80: num = ((b & 0x3f) << 8) + byte2int(_read_stream(stream, 1)) elif b & 0xe0 == 0xc0: num = (b & 0x1f) << 24 num += byte2int(_read_stream(stream, 1)) << 16 num += byte2int(_read_stream(stream, 1)) << 8 num += byte2int(_read_stream(stream, 1)) else: raise ConstructError('DotNetUInt encountered an invalid string') return num
def _parse(self, stream, context, path): byte = byte2int(stream_read(stream, 1, path)) if byte & 0x80 == 0: return byte num_bytes = byte & ~0x80 encoded_len = stream_read(stream, num_bytes, path) num = 0 for len_byte in iterateints(encoded_len): num = num << 8 + len_byte return num