3.5.1. Atom Protocol#
Caterpillar provides a special protocol for working with atoms. It is designed to incorporate packing and unpacking of data streams as well as calculating its size and measuring its type.
Changed in version 2.6.0: Reworked the CAPI and its components.
-
type CpAtomObject#
All classes that implement capabilities of an atom should inherit from this class. It stores optional C slots for
__pack__,__pack_many__,__unpack__,__unpack_many__,__size__,__type__and__bits__. Slots that are not configured raiseNotImplementedErrorwhen called through the Python methods.
-
PyTypeObject CpAtom_Type#
The type object of the
CpAtomclass.
Atoms may be implemented either as native CpAtomObject subclasses or
as normal Python objects exposing the corresponding special methods. The
CpAtom_* helpers use the native slot when available and fall back to Python
attribute/method lookup otherwise.
-
int CpAtom_HasPack(PyObject *o)#
-
int CpAtom_FastCanPack(PyObject *o, _coremodulestate *state)#
Return
1if the object provides an interface of packing other objects and0otherwise. Note that it returns1for classes with a__pack__()method, since the type of objects to be packed can not be determined by introspection.
-
int CpAtom_HasPackMany(PyObject *o)#
Return
1if the object exposes__pack_many__and0otherwise.
-
int CpAtom_HasUnpack(PyObject *o)#
Return
1if the object provides an interface of unpacking other objects and0otherwise. Note that it returns1for classes with a__unpack__()method, since the type of objects to be unpacked can not be determined by introspection.
-
int CpAtom_HasUnpackMany(PyObject *o)#
Return
1if the object exposes__unpack_many__and0otherwise.
-
int CpAtom_HasType(PyObject *o)#
Returns
1if the object provides a method of determining the type this object (usually an atom) represents and0otherwise. As all other functions, this one will simply check for the presence of the__type__()method.
-
int CpAtom_HasSize(PyObject *o)#
Searches for
__size__(), returns1if it is present and0otherwise.
-
int CpAtom_HasBits(PyObject *o)#
Searches for
__bits__and returns1if present.__bits__is used by bitfield and repeated native atoms and may be implemented as either a callable or an integer attribute on Python objects.