diff --git a/README.md b/README.md index afd10cd..65a8f36 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ u-msgpack-python is a lightweight [MessagePack](http://msgpack.org/) serializer and deserializer module written in pure Python, compatible with both Python 2 and 3, as well CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest [MessagePack specification](https://github.com/msgpack/msgpack/blob/master/spec.md). In particular, it supports the new binary, UTF-8 string, and application-defined ext types. -u-msgpack-python is currently distributed on PyPI: https://pypi.python.org/pypi/u-msgpack-python and as a single file: [umsgpack.py](https://raw.github.com/vsergeev/u-msgpack-python/master/umsgpack.py) +u-msgpack-python is currently distributed on [PyPI](https://pypi.python.org/pypi/u-msgpack-python) and as a single file: [umsgpack.py](https://raw.github.com/vsergeev/u-msgpack-python/master/umsgpack.py). ## Installation @@ -27,7 +27,7 @@ Basic Example: ``` python >>> import umsgpack >>> umsgpack.packb({u"compact": True, u"schema": 0}) -'\x82\xa7compact\xc3\xa6schema\x00' +b'\x82\xa7compact\xc3\xa6schema\x00' >>> umsgpack.unpackb(_) {u'compact': True, u'schema': 0} >>> @@ -35,13 +35,13 @@ Basic Example: A more complicated example: ``` python ->>> umsgpack.packb( [1, True, False, 0xffffffff, {u"foo": b"\x80\x01\x02", - u"bar": [1,2,3, {u"a": [1,2,3,{}]}]}, -1, 2.12345] ) -'\x97\x01\xc3\xc2\xce\xff\xff\xff\xff\x82\xa3foo\xc4\x03\x80\x01' -'\x02\xa3bar\x94\x01\x02\x03\x81\xa1a\x94\x01\x02\x03\x80\xff\xcb' -'@\x00\xfc\xd3Z\x85\x87\x94' +>>> umsgpack.packb([1, True, False, 0xffffffff, {u"foo": b"\x80\x01\x02", \ +... u"bar": [1,2,3, {u"a": [1,2,3,{}]}]}, -1, 2.12345]) +b'\x97\x01\xc3\xc2\xce\xff\xff\xff\xff\x82\xa3foo\xc4\x03\x80\x01\ +\x02\xa3bar\x94\x01\x02\x03\x81\xa1a\x94\x01\x02\x03\x80\xff\xcb\ +@\x00\xfc\xd3Z\x85\x87\x94' >>> umsgpack.unpackb(_) -[1, True, False, 4294967295, {u'foo': '\x80\x01\x02', +[1, True, False, 4294967295, {u'foo': b'\x80\x01\x02', \ u'bar': [1, 2, 3, {u'a': [1, 2, 3, {}]}]}, -1, 2.12345] >>> ``` @@ -62,19 +62,19 @@ Streaming serialization with file-like objects: >>> ``` -Encoding and decoding an application-defined Ext type: +Encoding and decoding a raw Ext type: ``` python -# Create an Ext object with type 0x05 and data b"\x01\x02\x03" ->>> foo = umsgpack.Ext(0x05, b"\x01\x02\x03") ->>> umsgpack.packb({u"special stuff": foo, u"awesome": True}) -b'\x82\xadspecial stuff\xc7\x03\x05\x01\x02\x03\xa7awesome\xc3' +>>> # Create an Ext object with type 0x05 and data b"\x01\x02\x03" +... foo = umsgpack.Ext(0x05, b"\x01\x02\x03") +>>> umsgpack.packb({u"stuff": foo, u"awesome": True}) +b'\x82\xa5stuff\xc7\x03\x05\x01\x02\x03\xa7awesome\xc3' >>> >>> bar = umsgpack.unpackb(_) ->>> print(bar["special stuff"]) +>>> print(bar['stuff']) Ext Object (Type: 0x05, Data: 0x01 0x02 0x03) ->>> bar["special stuff"].type +>>> bar['stuff'].type 5 ->>> bar["special stuff"].data +>>> bar['stuff'].data b'\x01\x02\x03' >>> ``` @@ -98,9 +98,8 @@ b'\x92\xd70\x00\x00\x80?\x00\x00\x00@\xc7\x18@20161017T00:12:53.719377' Python standard library style names `dump`, `dumps`, `load`, `loads` are also available: ``` python ->>> import umsgpack >>> umsgpack.dumps({u"compact": True, u"schema": 0}) -'\x82\xa7compact\xc3\xa6schema\x00' +b'\x82\xa7compact\xc3\xa6schema\x00' >>> umsgpack.loads(_) {u'compact': True, u'schema': 0} >>> diff --git a/msgpack.org.md b/msgpack.org.md index 02ff9ac..c03a35b 100644 --- a/msgpack.org.md +++ b/msgpack.org.md @@ -27,7 +27,7 @@ Basic Example: ``` python >>> import umsgpack >>> umsgpack.packb({u"compact": True, u"schema": 0}) -'\x82\xa7compact\xc3\xa6schema\x00' +b'\x82\xa7compact\xc3\xa6schema\x00' >>> umsgpack.unpackb(_) {u'compact': True, u'schema': 0} >>> @@ -36,13 +36,13 @@ Basic Example: A more complicated example: ``` python >>> umsgpack.packb( - [1, True, False, 0xffffffff, {u"foo": b"\x80\x01\x02", - u"bar": [1,2,3, {u"a": [1,2,3,{}]}]}, -1, 2.12345] ) -'\x97\x01\xc3\xc2\xce\xff\xff\xff\xff\x82\xa3foo\xc4\x03\x80\x01' -'\x02\xa3bar\x94\x01\x02\x03\x81\xa1a\x94\x01\x02\x03\x80\xff\xcb' -'@\x00\xfc\xd3Z\x85\x87\x94' +... [1, True, False, 0xffffffff, {u"foo": b"\x80\x01\x02", +... u"bar": [1,2,3, {u"a": [1,2,3,{}]}]}, -1, 2.12345] ) +b'\x97\x01\xc3\xc2\xce\xff\xff\xff\xff\x82\xa3foo\xc4\x03\x80\x01\ +\x02\xa3bar\x94\x01\x02\x03\x81\xa1a\x94\x01\x02\x03\x80\xff\xcb\ +@\x00\xfc\xd3Z\x85\x87\x94' >>> umsgpack.unpackb(_) -[1, True, False, 4294967295, {u'foo': '\x80\x01\x02', +[1, True, False, 4294967295, {u'foo': b'\x80\x01\x02', \ u'bar': [1, 2, 3, {u'a': [1, 2, 3, {}]}]}, -1, 2.12345] >>> ``` @@ -63,19 +63,19 @@ Streaming serialization with file-like objects: >>> ``` -Encoding and decoding an application-defined ext type: +Encoding and decoding a raw Ext type: ``` python >>> # Create an Ext object with type 0x05 and data b"\x01\x02\x03" ... foo = umsgpack.Ext(0x05, b"\x01\x02\x03") ->>> umsgpack.packb({u"special stuff": foo, u"awesome": True}) -b'\x82\xadspecial stuff\xc7\x03\x05\x01\x02\x03\xa7awesome\xc3' +>>> umsgpack.packb({u"stuff": foo, u"awesome": True}) +b'\x82\xa5stuff\xc7\x03\x05\x01\x02\x03\xa7awesome\xc3' >>> >>> bar = umsgpack.unpackb(_) ->>> print(bar["special stuff"]) +>>> print(bar['stuff']) Ext Object (Type: 0x05, Data: 0x01 0x02 0x03) ->>> bar["special stuff"].type +>>> bar['stuff'].type 5 ->>> bar["special stuff"].data +>>> bar['stuff'].data b'\x01\x02\x03' >>> ``` @@ -107,11 +107,9 @@ b'19377' Python standard library style names `dump`, `dumps`, `load`, `loads` are also available: - ``` python ->>> import umsgpack >>> umsgpack.dumps({u"compact": True, u"schema": 0}) -'\x82\xa7compact\xc3\xa6schema\x00' +b'\x82\xa7compact\xc3\xa6schema\x00' >>> umsgpack.loads(_) {u'compact': True, u'schema': 0} >>>