@@ -16,6 +16,28 @@ def p(s):
1616 assert p ('A' * 0x0123 ) == '\xc8 \x01 \x23 \x42 ' + 'A' * 0x0123 # ext 16
1717 assert p ('A' * 0x00012345 ) == '\xc9 \x00 \x01 \x23 \x45 \x42 ' + 'A' * 0x00012345 # ext 32
1818
19+ def test_unpack_extended_type ():
20+ class MyUnpacker (msgpack .Unpacker ):
21+ def read_extended_type (self , typecode , data ):
22+ return (typecode , data )
23+
24+ def u (s ):
25+ unpacker = MyUnpacker ()
26+ unpacker .feed (s )
27+ return unpacker .unpack_one ()
28+
29+ assert u ('\xd4 \x42 A' ) == (0x42 , 'A' ) # fixext 1
30+ assert u ('\xd5 \x42 AB' ) == (0x42 , 'AB' ) # fixext 2
31+ assert u ('\xd6 \x42 ABCD' ) == (0x42 , 'ABCD' ) # fixext 4
32+ assert u ('\xd7 \x42 ABCDEFGH' ) == (0x42 , 'ABCDEFGH' ) # fixext 8
33+ assert u ('\xd8 \x42 ' + 'A' * 16 ) == (0x42 , 'A' * 16 ) # fixext 16
34+ assert u ('\xc7 \x03 \x42 ABC' ) == (0x42 , 'ABC' ) # ext 8
35+ assert (u ('\xc8 \x01 \x23 \x42 ' + 'A' * 0x0123 ) ==
36+ (0x42 , 'A' * 0x0123 )) # ext 16
37+ assert (u ('\xc9 \x00 \x01 \x23 \x45 \x42 ' + 'A' * 0x00012345 ) ==
38+ (0x42 , 'A' * 0x00012345 )) # ext 32
39+
40+
1941def test_extension_type ():
2042 class MyPacker (msgpack .Packer ):
2143 def handle_unknown_type (self , obj ):
0 commit comments