3.7. Packing and Unpacking#
-
PyObject *CpAtom_TypeOf(PyObject *value)#
- Return value: New reference.
Returns a new reference containing the type reported by
value. Native atoms use theirob_typeslot; other objects are called through__type__. ReturnsNULLand sets an exception on failure.
-
int CpAtom_Pack(PyObject *pAtom, PyObject *pObj, PyObject *pContext)#
Packs the object
ousing the provided context and returns-1on error. The Proper use would be:PyObject *nAtom = ..., *nContext = ..., *nValue = ...; if (CpAtom_Pack(nAtom, nValue, nContext) < 0) goto error;
The provided context object must support the Context Protocol, which is not validated in this method.This function may raise NotImplementedError to indicate that this class does not support packing.
Added in version 2.6.0.
-
PyObject *CpAtom_Unpack(PyObject *pAtom, PyObject *pContext)#
- Return value: New reference.
Unpacks a value using
pAtomandpContext. Native atoms use theirob_unpackslot; Python objects are called through__unpack__. Returns a new reference on success orNULLon failure.Added in version 2.6.0.
-
int CpAtom_PackMany(PyObject *pAtom, PyObject *pObj, PyObject *pContext, PyObject *pLengthInfo)#
Packs a sequence of objects using
__pack_many__semantics. Returns0on success and-1on failure.Added in version 2.6.0.
-
PyObject *CpAtom_UnpackMany(PyObject *pAtom, PyObject *pContext, PyObject *pLengthInfo)#
- Return value: New reference.
Unpacks multiple objects using
__unpack_many__semantics and returns the result as a new reference.Added in version 2.6.0.
-
PyObject *CpAtom_Size(PyObject *pAtom, PyObject *pContext)#
- Return value: New reference.
Calculates the size of the object
pAtomusing contextpContextand returns the result. This method will return NULL if an error occurs while calling the target function.Added in version 2.6.0.
-
PyObject *CpAtom_BitsOf(PyObject *pAtom)#
- Return value: New reference.
Returns the bit count reported by
pAtom. Native atoms use theirob_bitsslot. Python objects are resolved through__bits__; if the attribute is callable it is called without arguments, otherwise the attribute value is returned as-is. Returns a new reference orNULLon failure.Added in version 2.6.0.