@@ -60,7 +60,7 @@ msgpack provides ``dumps`` and ``loads`` as an alias for compatibility with
60
60
.. code-block :: pycon
61
61
62
62
>>> import msgpack
63
- >>> msgpack.packb([1, 2, 3])
63
+ >>> msgpack.packb([1, 2, 3], use_bin_type=True )
64
64
'\x93\x01\x02\x03'
65
65
>>> msgpack.unpackb(_)
66
66
[1, 2, 3]
@@ -91,13 +91,13 @@ stream (or from bytes provided through its ``feed`` method).
91
91
92
92
buf = BytesIO()
93
93
for i in range (100 ):
94
- buf.write(msgpack.packb(range (i)))
94
+ buf.write(msgpack.packb(range (i), use_bin_type = True ))
95
95
96
96
buf.seek(0 )
97
97
98
98
unpacker = msgpack.Unpacker(buf)
99
99
for unpacked in unpacker:
100
- print unpacked
100
+ print ( unpacked)
101
101
102
102
103
103
Packing/unpacking of custom data type
@@ -109,7 +109,6 @@ It is also possible to pack/unpack custom data types. Here is an example for
109
109
.. code-block :: python
110
110
111
111
import datetime
112
-
113
112
import msgpack
114
113
115
114
useful_dict = {
@@ -128,7 +127,7 @@ It is also possible to pack/unpack custom data types. Here is an example for
128
127
return obj
129
128
130
129
131
- packed_dict = msgpack.packb(useful_dict, default = encode_datetime)
130
+ packed_dict = msgpack.packb(useful_dict, default = encode_datetime, use_bin_type = True )
132
131
this_dict_again = msgpack.unpackb(packed_dict, object_hook = decode_datetime)
133
132
134
133
``Unpacker ``'s ``object_hook `` callback receives a dict; the
@@ -208,6 +207,10 @@ the packer. If you do so, it will use a non-standard type called **bin** to
208
207
serialize byte arrays, and **raw ** becomes to mean **str **. If you want to
209
208
distinguish **bin ** and **raw ** in the unpacker, specify `encoding='utf-8' `.
210
209
210
+ **In future version, default value of ``use_bin_type`` will be changed to ``False``.
211
+ To avoid this change will break your code, you must specify it explicitly
212
+ even when you want to use old format. **
213
+
211
214
Note that Python 2 defaults to byte-arrays over Unicode strings:
212
215
213
216
.. code-block :: pycon
0 commit comments