8000 Update README (#393) · Anthchirp/msgpack-python@5399f81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5399f81

Browse files
authored
Update README (msgpack#393)
1 parent d8e3cf0 commit 5399f81

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

README.rst

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ msgpack is removed, and `import msgpack` fail.
3838

3939

4040
Compatibility with the old format
41-
^^^^^^^^^^^^^^^^^^^^^^----^^^^^^^
41+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4242

4343
You can use ``use_bin_type=False`` option to pack ``bytes``
4444
object into raw type in the old msgpack spec, instead of bin type in new msgpack spec.
@@ -49,6 +49,32 @@ It unpacks str (raw) type in msgpack into Python bytes.
4949
See note below for detail.
5050

5151

52+
Major breaking changes in msgpack 1.0
53+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
55+
* Python 2
56+
57+
* The extension module does not support Python 2 anymore.
58+
The pure Python implementation (``msgpack.fallback``) is used for Python 2.
59+
60+
* Packer
61+
62+
* ``use_bin_type=True`` by default. bytes are encoded in bin type in msgpack.
63+
**If you are still sing Python 2, you must use unicode for all string types.**
64+
You can use ``use_bin_type=False`` to encode into old msgpack format.
65+
* ``encoding`` option is removed. UTF-8 is used always.
66+
67+
* Unpacker
68+
69+
* ``raw=False`` by default. It assumes str types are valid UTF-8 string
70+
and decode them to Python str (unicode) object.
71+
* ``encdoding`` option is rmeoved. You can use ``raw=True`` to support old format.
72+
* Default value of ``max_buffer_size`` is changed from 0 to 100 MiB.
73+
* Default value of ``strict_map_key`` is changed to True to avoid hashdos.
74+
You need to pass ``strict_map_key=False`` if you have data which contain map keys
75+
which type is not bytes or str.
76+
77+
5278
Install
5379
-------
5480

@@ -270,27 +296,32 @@ To use the **ext** type, pass ``msgpack.ExtType`` object to packer.
270296
You can use it with ``default`` and ``ext_hook``. See below.
271297

272298

273-
Note about performance
274-
----------------------
299+
Security
300+
^^^^^^^^
301+
302+
To unpacking data received from unreliable source, msgpack provides
303+
two security options.
304+
305+
``max_buffer_size`` (default: 100*1024*1024) limits the internal buffer size.
306+
It is used to limit the preallocated list size too.
275307

276-
GC
277-
^^
308+
``strict_map_key`` (default: ``True``) limits the type of map keys to bytes and str.
309+
While msgpack spec doesn't limit the types of the map keys,
310+
there is a risk of the hashdos.
311+
If you need to support other types for map keys, use ``strict_map_key=False``.
312+
313+
314+
Performance tips
315+
^^^^^^^^^^^^^^^^
278316

279317
CPython's GC starts when growing allocated object.
280318
This means unpacking may cause useless GC.
281319
You can use ``gc.disable()`` when unpacking large message.
282320

283-
use_list option
284-
^^^^^^^^^^^^^^^
285-
286321
List is the default sequence type of Python.
287322
But tuple is lighter than list.
288323
You can use ``use_list=False`` while unpacking when performance is important.
289324

290-
Python's dict can't use list as key and MessagePack allows array for key of mapping.
291-
``use_list=False`` allows unpacking such message.
292-
Another way to unpacking such object is using ``object_pairs_hook``.
293-
294325

295326
Development
296327
-----------

msgpack/fallback.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ class Packer(object):
747747
748748
:param bool strict_types:
749749
If set to true, types will be checked to be exact. Derived classes
750-
from serializeable types will not be serialized and will be
750+
from serializable types will not be serialized and will be
751751
treated as unsupported type and forwarded to default.
752752
Additionally tuples will not be serialized as lists.
753753
This is useful when trying to implement accurate serialization
@@ -1014,7 +1014,7 @@ def bytes(self):
10141014
def reset(self):
10151015
"""Reset internal buffer.
10161016
1017-
This method is usaful only when autoreset=False.
1017+
This method is useful only when autoreset=False.
10181018
"""
10191019
self._buffer = StringIO()
10201020

0 commit comments

Comments
 (0)
0