slightly change to API

This commit is contained in:
Antonio Cuni 2013-10-18 15:03:58 +02:00
parent 5529dfe596
commit 522c4bfc79
2 changed files with 14 additions and 19 deletions

View file

@ -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)