mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-13 19:04:16 +00:00
slightly change to API
This commit is contained in:
parent
5529dfe596
commit
522c4bfc79
2 changed files with 14 additions and 19 deletions
|
|
@ -3,15 +3,16 @@ import msgpack
|
|||
|
||||
def test_extension_type():
|
||||
class MyPacker(msgpack.Packer):
|
||||
def handle_extended_type(self, obj):
|
||||
def handle_unknown_type(self, obj):
|
||||
if isinstance(obj, array.array):
|
||||
fmt = "ext 32"
|
||||
typecode = 123 # application specific typecode
|
||||
data = obj.tostring()
|
||||
return fmt, typecode, data
|
||||
self.pack_extended_type(fmt, typecode, data)
|
||||
return True
|
||||
|
||||
class MyUnpacker(msgpack.Unpacker):
|
||||
def handle_extended_type(self, typecode, data):
|
||||
def read_extended_type(self, typecode, data):
|
||||
assert typecode == 123
|
||||
obj = array.array('d')
|
||||
obj.fromstring(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue