新聞中心
數(shù)據(jù) marshal 操作支持
這些例程允許 C 代碼處理與 marshal 模塊所用相同數(shù)據(jù)格式的序列化對(duì)象。 其中有些函數(shù)可用來(lái)將數(shù)據(jù)寫(xiě)入這種序列化格式,另一些函數(shù)則可用來(lái)讀取并恢復(fù)數(shù)據(jù)。 用于存儲(chǔ) marshal 數(shù)據(jù)的文件必須以二進(jìn)制模式打開(kāi)。

十年的綿竹網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整綿竹建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“綿竹網(wǎng)站設(shè)計(jì)”,“綿竹網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
數(shù)字值在存儲(chǔ)時(shí)會(huì)將最低位字節(jié)放在開(kāi)頭。
此模塊支持兩種數(shù)據(jù)格式版本:第 0 版為歷史版本,第 1 版本會(huì)在文件和 marshal 反序列化中共享固化的字符串。 第 2 版本會(huì)對(duì)浮點(diǎn)數(shù)使用二進(jìn)制格式。 Py_MARSHAL_VERSION 指明了當(dāng)前文件的格式(當(dāng)前取值為 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.
void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)
將一個(gè) python 對(duì)象 value 以 marshal 格式寫(xiě)入 file。 version 指明文件格式的版本。
PyObject *PyMarshal_WriteObjectToString(PyObject *value, int version)
Return value: New reference.
返回一個(gè)包含 value 的 marshal 表示形式的字節(jié)串對(duì)象。 version 指明文件格式的版本。
以下函數(shù)允許讀取并恢復(fù)存儲(chǔ)為 marshal 格式的值。
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.
發(fā)生錯(cuò)誤時(shí),將設(shè)置適當(dāng)?shù)漠惓?(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.
發(fā)生錯(cuò)誤時(shí),將設(shè)置適當(dāng)?shù)漠惓?(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.
發(fā)生錯(cuò)誤時(shí),將設(shè)置適當(dāng)?shù)漠惓?(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.
發(fā)生錯(cuò)誤時(shí),將設(shè)置適當(dāng)?shù)漠惓?(EOFError, ValueError 或 TypeError) 并返回 NULL。
PyObject *PyMarshal_ReadObjectFromString(const char *data, Py_ssize_t len)
Return value: New reference.
從包含指向 data 的 len 個(gè)字節(jié)的字節(jié)緩沖區(qū)對(duì)應(yīng)的數(shù)據(jù)流返回一個(gè) Python 對(duì)象。
發(fā)生錯(cuò)誤時(shí),將設(shè)置適當(dāng)?shù)漠惓?(EOFError, ValueError 或 TypeError) 并返回 NULL。
分享文章:創(chuàng)新互聯(lián)Python教程:數(shù)據(jù)marshal操作支持
本文URL:http://www.dlmjj.cn/article/djohihs.html


咨詢
建站咨詢
