def unpackb(packed, object_hook=decode, **kwargs): """ Unpack a packed object. """ kwargs['object_hook'] = object_hook return _unpacker.unpackb(packed, **kwargs)
def unpackb(packed, object_hook=decode, encoding='utf-8', **kwargs): """ Unpack a packed object. """ kwargs['object_hook'] = object_hook return _unpacker.unpackb(packed, encoding=encoding, **kwargs)
def unpackb(packed, object_hook=decode, encoding="utf-8", **kwargs): """ Unpack a packed object. """ kwargs["object_hook"] = object_hook return _unpacker.unpackb(packed, encoding=encoding, **kwargs)
def unpackb(packed, **kwargs): """ Unpack a packed object. """ object_hook = kwargs.get('object_hook') kwargs['object_hook'] = functools.partial(decode, chain=object_hook) return _unpacker.unpackb(packed, **kwargs)
def unpack(stream, **kwargs): """ Unpack an object from `stream`. Raises `ExtraData` when `packed` contains extra bytes. See :class:`Unpacker` for options. """ return unpackb(stream.read(), **kwargs)
def unpack(stream, **kwargs): """ Unpack an object from `stream`. Raises `ExtraData` when `stream` contains extra bytes. See :class:`Unpacker` for options. """ data = stream.read() return unpackb(data, **kwargs)
def simple(name, data): if has_ext: profile("packing %s (ext)" % name, lambda: _packer.packb(data)) profile('packing %s (fallback)' % name, lambda: fallback.packb(data)) data = fallback.packb(data) if has_ext: profile('unpacking %s (ext)' % name, lambda: _unpacker.unpackb(data)) profile('unpacking %s (fallback)' % name, lambda: fallback.unpackb(data))
def simple(name, data): if has_ext: packer = _cmsgpack.Packer() profile("packing %s (ext)" % name, lambda: packer.pack(data)) packer = fallback.Packer() profile("packing %s (fallback)" % name, lambda: packer.pack(data)) data = packer.pack(data) if has_ext: profile("unpacking %s (ext)" % name, lambda: _cmsgpack.unpackb(data)) profile("unpacking %s (fallback)" % name, lambda: fallback.unpackb(data))
def _read(self): while self._buffer_size > self._unpacker.tell(): # map_start_indicator self._read_next() map_name = self._read_next_string() LOG.trace(f"Reading map {map_name}") records = {} self._tables[map_name] = records # read_version self._read_next() # read_count read_count = self._read_next() assert read_count == 0, f"Unexpected read count: {read_count}" write_count = self._read_next() if write_count: for _ in range(write_count): k = self._read_next_entry() val = self._read_next_entry() if map_name in self._msgpacked_tables: k = msgpack.unpackb(k, **UNPACK_ARGS) val = msgpack.unpackb(val, **UNPACK_ARGS) if map_name == NODES_TABLE_NAME: k = str(k) records[k] = val remove_count = self._read_next() if remove_count: for _ in range(remove_count): k = self._read_next_entry() if map_name in self._msgpacked_tables: k = msgpack.unpackb(k, **UNPACK_ARGS) records[k] = None LOG.trace( f"Found {read_count} reads, {write_count} writes, and {remove_count} removes" )
def extract_msgpacked_data(data: bytes): return msgpack.unpackb(data, **UNPACK_ARGS)