Soporte de empaquetado (marshalling) de datos

Estas rutinas permiten que el código C funcione con objetos serializados utilizando el mismo formato de datos que el módulo marshal. Hay funciones para escribir datos en el formato de serialización y funciones adicionales que se pueden usar para volver a leer los datos. Los archivos utilizados para almacenar datos ordenados deben abrirse en modo binario.

Los valores numéricos se almacenan con el byte menos significativo primero.

El módulo admite dos versiones del formato de datos: la versión 0 es la versión histórica, la versión 1 comparte cadenas de caracteres internas en el archivo y al desempaquetar (unmarshalling). La versión 2 usa un formato binario para números de punto flotante. Py_MARSHAL_VERSION indica el formato de archivo actual (actualmente 2).

void PyMarshal_WriteLongToFile(long value, FILE *file, int version)

Marshal a long integer, value, to file. This will only write the least-significant 32 bits of value; regardless of the size of the native long type. version indicates the file format.

This function can fail, in which case it sets the error indicator. Use PyErr_Occurred() to check for that.

void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)

Empaqueta (marshal) un objeto Python, value, a un archivo file. version indica el formato del archivo.

This function can fail, in which case it sets the error indicator. Use PyErr_Occurred() to check for that.

PyObject *PyMarshal_WriteObjectToString(PyObject *value, int version)
Return value: New reference.

Retorna un objeto de bytes que contiene la representación empaquetada (marshalled) de value. version indica el formato del archivo.

Las siguientes funciones permiten volver a leer los valores empaquetados (marshalled).

long PyMarshal_ReadLongFromFile(FILE *file)

Return a C long from the data stream in a FILE* opened for reading. Only a 32-bit value can be read in using this function, regardless of the native size of long.

En caso de error, establece la excepción apropiada (EOFError) y retorna -1.

int PyMarshal_ReadShortFromFile(FILE *file)

Return a C short from the data stream in a FILE* opened for reading. Only a 16-bit value can be read in using this function, regardless of the native size of short.

En caso de error, establece la excepción apropiada (EOFError) y retorna -1.

PyObject *PyMarshal_ReadObjectFromFile(FILE *file)
Return value: New reference.

Return a Python object from the data stream in a FILE* opened for reading.

En caso de error, establece la excepción apropiada (EOFError, ValueError o TypeError) y retorna NULL.

PyObject *PyMarshal_ReadLastObjectFromFile(FILE *file)
Return value: New reference.

Return a Python object from the data stream in a FILE* opened for reading. Unlike PyMarshal_ReadObjectFromFile(), this function assumes that no further objects will be read from the file, allowing it to aggressively load file data into memory so that the de-serialization can operate from data in memory rather than reading a byte at a time from the file. Only use these variant if you are certain that you won’t be reading anything else from the file.

En caso de error, establece la excepción apropiada (EOFError, ValueError o TypeError) y retorna NULL.

PyObject *PyMarshal_ReadObjectFromString(const char *data, Py_ssize_t len)
Return value: New reference.

Retorna un objeto Python del flujo de datos en un búfer de bytes que contiene len bytes a los que apunta data.

En caso de error, establece la excepción apropiada (EOFError, ValueError o TypeError) y retorna NULL.