Class to unpack values from buffer object
The buffer object is usually a string. Caches compiled struct format strings so that repeated unpacking with the same format string should be faster than using struct.unpack directly.
Examples
>>> a = '1234567890' #23dt : bytes
>>> upk = Unpacker(a)
>>> upk.unpack('2s') #23dt next : bytes
('12',)
>>> upk.unpack('2s') #23dt next : bytes
('34',)
>>> upk.ptr
4
>>> upk.read(3) #23dt next : bytes
'567'
>>> upk.ptr
7
Initialize unpacker
| Parameters : | buf : buffer
ptr : int, optional
endian : None or str, optional
|
|---|
Return byte string of length n_bytes at current position
Returns sub-string from self.buf and updates self.ptr to the position after the read data.
| Parameters : | n_bytes : int, optional
|
|---|---|
| Returns : | s : byte string |
Unpack values from contained buffer
Unpacks values from self.buf and updates self.ptr to the position after the read data.
| Parameters : | fmt : str
|
|---|---|
| Returns : | values : tuple
|