Python Msgpack Module: Packb and Newlines

Python Msgpack Module: Packb and Newlines

Currently we are using json to code\decode data in our data processing software. But we found any JSON implementation slow - we tried simplejson, ujson etc. - so we're looking for an alternative.

We use some other programs to work with data, and newline symbol is a terminator for each piece of data. In other words, we'd like to avoid serializators that might put newline symbol into dumped objects.

I tried msgpack on a small piece of data, and it seems it does not put newline symbol (pickle does). And it's quite fast.

Could anybody tell me if newlines will not be used in any dumped object, if I use msgpack packb() method? Thanks

1 Answer

Yes, msgpack does add newlines (unfortunately):

>>> import msgpack
>>> s = msgpack.packb({"a":10,"b":13})
>>> s
'\x82\xa1a\n\xa1b\r'
>>> '\r' in s
True
>>> '\n' in s
True
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.