File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,30 @@ class Expected(NamedTuple):
100
100
101
101
102
102
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
+ """
103
127
integers : List [int ] = []
104
128
total : int = 0
105
129
You can’t perform that action at this time.
0 commit comments