I'm looking for an easy way of packing/unpacking data structures for sending over the network:
on client just before sending:
a = ((1,2),(11,22,),(111,222))
message = pack(a)
and then on server:
a = unpack(message)
Is there a library that could do pack/unpack magic? Thanks in advance
Looks like JSON might fit the bill. It's simple, and it's in the Python standard library.
It might not be too happy about the tuples, though:
>>> import json
>>> a = ((1,2),(11,22,),(111,222))
>>> print a
((1, 2), (11, 22), (111, 222))
>>> message = json.dumps(a)
>>> message
'[[1, 2], [11, 22], [111, 222]]'
>>> b = json.loads(message)
>>> b
[[1, 2], [11, 22], [111, 222]]
Whether or not that's a problem is for you to decide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With