From fe1e69574a78135b5aeef3ead52a5944ca4af7f3 Mon Sep 17 00:00:00 2001 From: "Vanya A. Sergeev" Date: Sun, 25 Sep 2016 02:59:55 -0700 Subject: [PATCH] add use_ordered_dict option usage to readme --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c7df1c..940a03b 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,21 @@ The streaming `pack()`/`dump()` and `unpack()`/`load()` functions allow packing >>> ``` -## Compatibility Mode +## Options + +### Ordered Dictionaries + +The unpacking functions provide a `use_ordered_dict` option to unpack MessagePack maps into the `collections.OrderedDict` type, rather than the unordered `dict` type, to preserve the order of deserialized MessagePack maps. + +``` python +>>> umsgpack.unpackb(b'\x82\xa7compact\xc3\xa6schema\x00') +{'compact': True, 'schema': 0} +>>> umsgpack.unpackb(b'\x82\xa7compact\xc3\xa6schema\x00', use_ordered_dict=True) +OrderedDict([('compact', True), ('schema', 0)]) +>>> +``` + +### Compatibility Mode u-msgpack-python offers a compatibility mode for the [old specification](https://github.com/msgpack/msgpack/blob/master/spec-old.md) to handle the old "raw" bytes msgpack type. When the compatibility mode is enabled, u-msgpack-python will serialize both unicode strings and bytes into the old "raw" msgpack type, and deserialize the "raw" msgpack type into bytes. To enable compatibility mode, simply set the `compatibility` boolean of the umsgpack module to `True`.