def test_unpack_utf8_string(): length = b"\x00\x09" utf8_string = b"\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" encoded = length + utf8_string (value, bytes_consumed) = DecodeUtils.unpack_utf8_string(encoded) assert bytes_consumed == 11 assert value == utf8_string.decode("utf-8")
def test_unpack_prelude(): data = b"\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03" prelude = DecodeUtils.unpack_prelude(data) assert prelude == ((1, 2, 3), 12)
def test_unpack_byte_array_int(): (value, array_bytes_consumed) = DecodeUtils.unpack_byte_array( b"\x00\x00\x00\x10application/json", length_byte_size=4 ) assert array_bytes_consumed == 20 assert value == b"application/json"
def test_unpack_array_short(): test_bytes = b"\x00\x10application/json" (value, bytes_consumed) = DecodeUtils.unpack_byte_array(test_bytes) assert bytes_consumed == 18 assert value == b"application/json"
def test_unpack_int64(): test_bytes = b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE" (value, bytes_consumed) = DecodeUtils.unpack_int64(test_bytes) assert bytes_consumed == 8 assert value == -2
def test_unpack_int32(): (value, bytes_consumed) = DecodeUtils.unpack_int32(b"\xFF\xFF\xFF\xFE") assert bytes_consumed == 4 assert value == -2
def test_unpack_uint32(): (value, bytes_consumed) = DecodeUtils.unpack_uint32(b"\xDE\xAD\xBE\xEF") assert bytes_consumed == 4 assert value == 0xDEADBEEF
def test_unpack_uint8(): (value, bytes_consumed) = DecodeUtils.unpack_uint8(b"\xDE") assert bytes_consumed == 1 assert value == 0xDE