Esempio n. 1
0
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_equal(bytes_consumed, 11)
    assert_equal(value, utf8_string.decode('utf-8'))
Esempio n. 2
0
def test_unpack_prelude():
    data = b'\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03'
    prelude = DecodeUtils.unpack_prelude(data)
    assert_equal(prelude, ((1, 2, 3), 12))
Esempio n. 3
0
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_equal(array_bytes_consumed, 20)
    assert_equal(value, b'application/json')
Esempio n. 4
0
def test_unpack_int64():
    test_bytes = b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE'
    (value, bytes_consumed) = DecodeUtils.unpack_int64(test_bytes)
    assert_equal(bytes_consumed, 8)
    assert_equal(value, -2)
Esempio n. 5
0
def test_unpack_array_short():
    test_bytes = b'\x00\x10application/json'
    (value, bytes_consumed) = DecodeUtils.unpack_byte_array(test_bytes)
    assert_equal(bytes_consumed, 18)
    assert_equal(value, b'application/json')
Esempio n. 6
0
def test_unpack_uint32():
    (value, bytes_consumed) = DecodeUtils.unpack_uint32(b'\xDE\xAD\xBE\xEF')
    assert_equal(bytes_consumed, 4)
    assert_equal(value, 0xDEADBEEF)
Esempio n. 7
0
def test_unpack_int32():
    (value, bytes_consumed) = DecodeUtils.unpack_int32(b'\xFF\xFF\xFF\xFE')
    assert_equal(bytes_consumed, 4)
    assert_equal(value, -2)
Esempio n. 8
0
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'
Esempio n. 9
0
def test_unpack_uint8():
    (value, bytes_consumed) = DecodeUtils.unpack_uint8(b'\xDE')
    assert_equal(bytes_consumed, 1)
    assert_equal(value, 0xDE)
Esempio n. 10
0
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'
Esempio n. 11
0
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
Esempio n. 12
0
def test_unpack_int32():
    (value, bytes_consumed) = DecodeUtils.unpack_int32(b'\xFF\xFF\xFF\xFE')
    assert bytes_consumed == 4
    assert value == -2
Esempio n. 13
0
def test_unpack_uint32():
    (value, bytes_consumed) = DecodeUtils.unpack_uint32(b'\xDE\xAD\xBE\xEF')
    assert bytes_consumed == 4
    assert value == 0xDEADBEEF
Esempio n. 14
0
def test_unpack_uint8():
    (value, bytes_consumed) = DecodeUtils.unpack_uint8(b'\xDE')
    assert bytes_consumed == 1
    assert value == 0xDE