text
stringlengths
0
828
""""""Unpack a utf-8 string encoded as described in MQTT Version
3.1.1 section 1.5.3 line 177. This is a 16-bit unsigned length
followed by a utf-8 encoded string.
Returns
-------
int
Number of bytes consumed
bytes
A bytes object extracted from the underlying stream.
""""""
num_bytes_consumed, b = decode_bytes(self.__f)
self.__num_bytes_consumed += num_bytes_consumed
return num_bytes_consumed, b"
641,"def unpack_varint(self, max_bytes):
""""""Decode variable integer using algorithm similar to that described
in MQTT Version 3.1.1 line 297.
Parameters
----------
max_bytes: int or None
If a varint cannot be constructed using `max_bytes` or fewer
from f then raises a `DecodeError`. If None then there is no
maximum number of bytes.
Raises
-------
DecodeError
When length is greater than max_bytes.
UnderflowDecodeError
When file ends before enough bytes can be read to construct the
varint.
Returns
-------
int
Number of bytes consumed.
int
Value extracted from `f`.
""""""
num_bytes_consumed, value = decode_varint(self.__f, max_bytes)
self.__num_bytes_consumed += num_bytes_consumed
return num_bytes_consumed, value"
642,"def read(self, num_bytes):
""""""Read `num_bytes` and return them.
Parameters
----------
num_bytes : int
Number of bytes to extract from the underlying stream.
Raises
------
UnderflowDecodeError
Raised when a read failed to extract enough bytes from the
underlying stream to extract the bytes.
Returns
-------
bytes
A bytes object extracted from underlying stream.
""""""
buf = self.__f.read(num_bytes)
assert len(buf) <= num_bytes
if len(buf) < num_bytes:
raise UnderflowDecodeError()
self.__num_bytes_consumed += num_bytes
return buf"
643,"def read(self, max_bytes=1):
""""""Read at most `max_bytes` from internal buffer.
Parameters
-----------
max_bytes: int
Maximum number of bytes to read.
Returns
--------
bytes
Bytes extracted from internal buffer. Length may be less
than ``max_bytes``. On end-of file returns a bytes object
with zero-length.
""""""
if self.limit is None:
b = self.__f.read(max_bytes)
else:
if self.__num_bytes_consumed + max_bytes > self.limit:
max_bytes = self.limit - self.__num_bytes_consumed
b = self.__f.read(max_bytes)
self.__num_bytes_consumed += len(b)
return b"
644,"def read(self, max_bytes=1):
""""""Read at most `max_bytes` from internal buffer.
Parameters
-----------