@@ -212,49 +212,76 @@ def unpackb(object packed, *, object object_hook=None, object list_hook=None,
212
212
213
213
214
214
cdef class Unpacker(object ):
215
- """
216
- MessagePack Packer
215
+ """ Streaming unpacker.
216
+
217
+ Arguments:
217
218
218
- Usage::
219
+ :param file_like:
220
+ File-like object having `.read(n)` method.
221
+ If specified, unpacker reads serialized data from it and :meth:`feed()` is not usable.
219
222
220
- packer = Packer()
221
- astream.write(packer.pack(a))
222
- astream.write(packer.pack(b))
223
+ :param int read_size:
224
+ Used as `file_like.read(read_size)`. (default: `min(16*1024, max_buffer_size)`)
223
225
224
- Packer's constructor has some keyword arguments:
226
+ :param bool use_list:
227
+ If true, unpack msgpack array to Python list.
228
+ Otherwise, unpack to Python tuple. (default: True)
225
229
226
- :param callable default :
227
- Convert user type to builtin type that Packer supports .
228
- See also simplejson's document .
230
+ :param bool raw :
231
+ If true, unpack msgpack raw to Python bytes .
232
+ Otherwise, unpack to Python str by decoding with UTF-8 encoding (default) .
229
233
230
- :param bool use_single_float :
231
- Use single precision float type for float. (default: False)
234
+ :param int timestamp :
235
+ Control how timestamp type is unpacked:
232
236
233
- :param bool autoreset:
234
- Reset buffer after each pack and return its content as `bytes`. (default: True).
235
- If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
237
+ 0 - Timestamp
238
+ 1 - float (Seconds from the EPOCH)
239
+ 2 - int (Nanoseconds from the EPOCH)
240
+ 3 - datetime.datetime (UTC). Python 2 is not supported.
236
241
237
- :param bool use_bin_type:
238
- Use bin type introduced in msgpack spec 2.0 for bytes.
239
- It also enables str8 type for unicode. (default: True)
242
+ :param bool strict_map_key:
243
+ If true (default), only str or bytes are accepted for map (dict) keys.
240
244
241
- :param bool strict_types:
242
- If set to true, types will be checked to be exact. Derived classes
243
- from serializable types will not be serialized and will be
244
- treated as unsupported type and forwarded to default.
245
- Additionally tuples will not be serialized as lists.
246
- This is useful when trying to implement accurate serialization
247
- for python types.
245
+ :param callable object_hook:
246
+ When specified, it should be callable.
247
+ Unpacker calls it with a dict argument after unpacking msgpack map.
248
+ (See also simplejson)
248
249
249
- :param bool datetime:
250
- If set to true, datetime with tzinfo is packed into Timestamp type.
251
- Note that the tzinfo is stripped in the timestamp.
252
- You can get UTC datetime with `timestamp=3` option of the Unpacker.
253
- (Python 2 is not supported).
250
+ :param callable object_pairs_hook:
251
+ When specified, it should be callable.
252
+ Unpacker calls it with a list of key-value pairs after unpacking msgpack map.
253
+ (See also simplejson)
254
254
255
255
:param str unicode_errors:
256
- The error handler for encoding unicode. (default: 'strict')
257
- DO NOT USE THIS!! This option is kept for very specific usage.
256
+ The error handler for decoding unicode. (default: 'strict')
257
+ This option should be used only when you have msgpack data which
258
+ contains invalid UTF-8 string.
259
+
260
+ :param int max_buffer_size:
261
+ Limits size of data waiting unpacked. 0 means 2**32-1.
262
+ The default value is 100*1024*1024 (100MiB).
263
+ Raises `BufferFull` exception when it is insufficient.
264
+ You should set this parameter when unpacking data from untrusted source.
265
+
266
+ :param int max_str_len:
267
+ Deprecated, use *max_buffer_size* instead.
268
+ Limits max length of str. (default: max_buffer_size)
269
+
270
+ :param int max_bin_len:
271
+ Deprecated, use *max_buffer_size* instead.
272
+ Limits max length of bin. (default: max_buffer_size)
273
+
274
+ :param int max_array_len:
275
+ Limits max length of array.
276
+ (default: max_buffer_size)
277
+
278
+ :param int max_map_len:
279
+ Limits max length of map.
280
+ (default: max_buffer_size//2)
281
+
282
+ :param int max_ext_len:
283
+ Deprecated, use *max_buffer_size* instead.
284
+ Limits max size of ext type. (default: max_buffer_size)
258
285
259
286
Example of streaming deserialize from file-like object::
260
287
0 commit comments