OpenQuizz
Une application de gestion des contenus pédagogiques
Packer Class Reference
Inheritance diagram for Packer:
Collaboration diagram for Packer:

Public Member Functions

def __init__ (self, default=None, use_single_float=False, autoreset=True, use_bin_type=True, strict_types=False, datetime=False, unicode_errors=None)
 
def pack (self, obj)
 
def pack_map_pairs (self, pairs)
 
def pack_array_header (self, n)
 
def pack_map_header (self, n)
 
def pack_ext_type (self, typecode, data)
 
def bytes (self)
 
def reset (self)
 
def getbuffer (self)
 

Detailed Description

MessagePack Packer

Usage::

    packer = Packer()
    astream.write(packer.pack(a))
    astream.write(packer.pack(b))

Packer's constructor has some keyword arguments:

:param callable default:
    Convert user type to builtin type that Packer supports.
    See also simplejson's document.

:param bool use_single_float:
    Use single precision float type for float. (default: False)

:param bool autoreset:
    Reset buffer after each pack and return its content as `bytes`. (default: True).
    If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.

:param bool use_bin_type:
    Use bin type introduced in msgpack spec 2.0 for bytes.
    It also enables str8 type for unicode. (default: True)

:param bool strict_types:
    If set to true, types will be checked to be exact. Derived classes
    from serializable types will not be serialized and will be
    treated as unsupported type and forwarded to default.
    Additionally tuples will not be serialized as lists.
    This is useful when trying to implement accurate serialization
    for python types.

:param bool datetime:
    If set to true, datetime with tzinfo is packed into Timestamp type.
    Note that the tzinfo is stripped in the timestamp.
    You can get UTC datetime with `timestamp=3` option of the Unpacker.
    (Python 2 is not supported).

:param str unicode_errors:
    The error handler for encoding unicode. (default: 'strict')
    DO NOT USE THIS!!  This option is kept for very specific usage.

Example of streaming deserialize from file-like object::

    unpacker = Unpacker(file_like)
    for o in unpacker:
        process(o)

Example of streaming deserialize from socket::

    unpacker = Unpacker()
    while True:
        buf = sock.recv(1024**2)
        if not buf:
            break
        unpacker.feed(buf)
        for o in unpacker:
            process(o)

Raises ``ExtraData`` when *packed* contains extra bytes.
Raises ``OutOfData`` when *packed* is incomplete.
Raises ``FormatError`` when *packed* is not valid msgpack.
Raises ``StackError`` when *packed* contains too nested.
Other exceptions can be raised during unpacking.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  default = None,
  use_single_float = False,
  autoreset = True,
  use_bin_type = True,
  strict_types = False,
  datetime = False,
  unicode_errors = None 
)

Member Function Documentation

◆ bytes()

def bytes (   self)
Return internal buffer contents as bytes object

◆ getbuffer()

def getbuffer (   self)
Return view of internal buffer.

◆ pack()

def pack (   self,
  obj 
)

◆ pack_array_header()

def pack_array_header (   self,
  n 
)

◆ pack_ext_type()

def pack_ext_type (   self,
  typecode,
  data 
)

◆ pack_map_header()

def pack_map_header (   self,
  n 
)

◆ pack_map_pairs()

def pack_map_pairs (   self,
  pairs 
)

◆ reset()

def reset (   self)
Reset internal buffer.

This method is useful only when autoreset=False.

The documentation for this class was generated from the following file: