summaryrefslogtreecommitdiff
path: root/Doc/library/struct.rst
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-04-27 00:20:04 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2013-04-27 00:20:04 +0200
commit9f146819598013046dfb4d24ef4f2a748e6c5930 (patch)
tree468d30a5220017c04229325c3ce3d29677db71b6 /Doc/library/struct.rst
parent3da670749a25a9ea068c427f6b03812b92e75d13 (diff)
downloadcpython-git-9f146819598013046dfb4d24ef4f2a748e6c5930.tar.gz
Issue #17804: New function ``struct.iter_unpack`` allows for streaming struct unpacking.
Diffstat (limited to 'Doc/library/struct.rst')
-rw-r--r--Doc/library/struct.rst20
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst
index 994506c2fe..f2ea361929 100644
--- a/Doc/library/struct.rst
+++ b/Doc/library/struct.rst
@@ -66,6 +66,19 @@ The module defines the following exception and functions:
format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``).
+.. function:: iter_unpack(fmt, buffer)
+
+ Iteratively unpack from the buffer *buffer* according to the format
+ string *fmt*. This function returns an iterator which will read
+ equally-sized chunks from the buffer until all its contents have been
+ consumed. The buffer's size in bytes must be a multiple of the amount
+ of data required by the format, as reflected by :func:`calcsize`.
+
+ Each iteration yields a tuple as specified by the format string.
+
+ .. versionadded:: 3.4
+
+
.. function:: calcsize(fmt)
Return the size of the struct (and hence of the bytes object produced by
@@ -388,6 +401,13 @@ The :mod:`struct` module also defines the following type:
(``len(buffer[offset:])`` must be at least :attr:`self.size`).
+ .. method:: iter_unpack(buffer)
+
+ Identical to the :func:`iter_unpack` function, using the compiled format.
+ (``len(buffer)`` must be a multiple of :attr:`self.size`).
+
+ .. versionadded:: 3.4
+
.. attribute:: format
The format string used to construct this Struct object.