Skip to content

Commit f21c0c0

Browse files
uvarint: add docstring for the expect function
1 parent 0d8bc99 commit f21c0c0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

uvarint.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ class Expected(NamedTuple):
100100

101101

102102
def expect(count: int, buffer: bytes, limit: Number = 9) -> Expected:
103+
"""Decodes the expected number of uvarints in the given buffer.
104+
105+
In addition to the list of decoded integers,
106+
the total number of bytes read is returned.
107+
This allows the caller to seek past the decoded data in the buffer.
108+
109+
Should the buffer not contain the expected amount of uvarints,
110+
ValueError will be raised.
111+
112+
The buffer may be None or empty if the expected count is zero.
113+
The result will be an empty list and a total of zero bytes read.
114+
115+
To prevent denial of service attacks, memory consumption is limited.
116+
By default, a limit of 9 bytes will be imposed on individual uvarints.
117+
The function will decode values in the interval [0, 2^63 - 1]
118+
and will raise OverflowError for bigger integers.
119+
This limit can be changed through the limit keyword argument.
120+
It can be removed entirely by passing math.inf.
121+
122+
:param count: expected number of uvarints in the buffer
123+
:param buffer: bytes containing at least one uvarint encoded integer
124+
:param limit: maximum number of bytes to decode
125+
:return: list of decoded integers and total number of bytes read
126+
"""
103127
integers: List[int] = []
104128
total: int = 0
105129

0 commit comments

Comments
 (0)