def method_arguments_opaque_decode(buf: bytes) -> List[MethodArgument]:
    args = list()
    method_args_reader = StreamReader(buf)

    while not method_args_reader.done_reading():
        arg = StreamReader(method_args_reader.read_bytes())
        name = arg.read_bytes()  # not using the arg name
        arg_type = arg.read_uint16()

        if arg_type == 0:
            val = arg.read_uint32()
            args.append(Uint32Arg(val))
        elif arg_type == 1:
            val = arg.read_uint64()
            args.append(Uint64Arg(val))
        elif arg_type == 2:
            val = arg.read_string()
            args.append(StringArg(val))
        elif arg_type == 3:
            val = arg.read_bytes()
            args.append(BytesArg(val))
        else:
            raise ValueError(
                f'received MethodArgument {name} has an unknown type: {arg_type}'
            )

    return args
Esempio n. 2
0
 def test_read_uint32(self):
     stream = bytes([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
     reader = StreamReader(stream)
     expected = 4294967295
     self.assertEqual(expected, reader.read_uint32())
     reader.close()