데이터 마샬링 지원

이러한 루틴은 C 코드가 marshal 모듈과 같은 데이터 형식을 사용하여 직렬화된 객체로 작업 할 수 있도록 합니다. 직렬화 형식으로 데이터를 쓰는 함수와 데이터를 다시 읽는 데 사용할 수 있는 추가 함수가 있습니다. 마샬링 된 데이터를 저장하는 데 사용되는 파일은 바이너리 모드로 열어야 합니다.

숫자 값은 최하위 바이트가 먼저 저장됩니다.

이 모듈은 두 가지 버전의 데이터 형식을 지원합니다: 버전 0은 역사적인 버전이고, 버전 1은 파일에서와 역 마샬링할 때 인턴(intern) 된 문자열을 공유합니다. 버전 2는 부동 소수점 숫자에 대해 바이너리 형식을 사용합니다. Py_MARSHAL_VERSION은 현재 파일 형식을 나타냅니다 (현재 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)

파이썬 객체 valuefile로 마샬합니다. version은 파일 형식을 나타냅니다.

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.

마샬된 value 표현을 포함한 바이트열 객체를 반환합니다. version은 파일 형식을 나타냅니다.

다음 함수를 사용하면 마샬된 값을 다시 읽을 수 있습니다.

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.

에러 시, 적절한 예외(EOFError)를 설정하고 -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.

에러 시, 적절한 예외(EOFError)를 설정하고 -1을 반환합니다.

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

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

에러 시, 적절한 예외(EOFError, ValueError 또는 TypeError)를 설정하고 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.

에러 시, 적절한 예외(EOFError, ValueError 또는 TypeError)를 설정하고 NULL을 반환합니다.

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

data가 가리키는 len 바이트를 포함하는 바이트 버퍼의 데이터 스트림에서 파이썬 객체를 반환합니다.

에러 시, 적절한 예외(EOFError, ValueError 또는 TypeError)를 설정하고 NULL을 반환합니다.