데이터 마샬링 지원¶
이러한 루틴은 C 코드가 marshal 모듈과 같은 데이터 형식을 사용하여 직렬화된 객체로 작업 할 수 있도록 합니다. 직렬화 형식으로 데이터를 쓰는 함수와 데이터를 다시 읽는 데 사용할 수 있는 추가 함수가 있습니다. 마샬링 된 데이터를 저장하는 데 사용되는 파일은 바이너리 모드로 열어야 합니다.
숫자 값은 최하위 바이트가 먼저 저장됩니다.
The module supports several versions of the data format; see
the Python module documentation for details.
-
Py_MARSHAL_VERSION¶
The current format version. See
marshal.version.
-
void PyMarshal_WriteLongToFile(long value, FILE *file, int version)¶
long 정수 value를 file로 마샬합니다. value의 최하위 32비트 만 기록합니다; 기본 long 형의 크기와 관계없이. version은 파일 형식을 나타냅니다.
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)¶
파이썬 객체 value를 file로 마샬합니다. 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)¶
- 반환값: 새 참조.
마샬된 value 표현을 포함한 바이트열 객체를 반환합니다. version은 파일 형식을 나타냅니다.
다음 함수를 사용하면 마샬된 값을 다시 읽을 수 있습니다.
-
long PyMarshal_ReadLongFromFile(FILE *file)¶
읽기 위해 열린 FILE*의 데이터 스트림에서 C long을 반환합니다. 이 함수를 사용하면 long의 기본 크기와 관계없이 32비트 값만 읽을 수 있습니다.
에러 시, 적절한 예외(
EOFError)를 설정하고-1을 반환합니다.
-
int PyMarshal_ReadShortFromFile(FILE *file)¶
읽기 위해 열린 FILE*의 데이터 스트림에서 C short를 반환합니다. 이 함수를 사용하면 short의 기본 크기와 관계없이 16비트 값만 읽을 수 있습니다.
에러 시, 적절한 예외(
EOFError)를 설정하고-1을 반환합니다.
-
PyObject *PyMarshal_ReadObjectFromFile(FILE *file)¶
- 반환값: 새 참조.
읽기 위해 열린 FILE*의 데이터 스트림에서 파이썬 객체를 반환합니다.
에러 시, 적절한 예외(
EOFError,ValueError또는TypeError)를 설정하고NULL을 반환합니다.
-
PyObject *PyMarshal_ReadLastObjectFromFile(FILE *file)¶
- 반환값: 새 참조.
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 this 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)¶
- 반환값: 새 참조.
data가 가리키는 len 바이트를 포함하는 바이트 버퍼의 데이터 스트림에서 파이썬 객체를 반환합니다.
에러 시, 적절한 예외(
EOFError,ValueError또는TypeError)를 설정하고NULL을 반환합니다.