| 104 | static PyMMKVHandler g_pyHandler; |
| 105 | |
| 106 | PYBIND11_MODULE(mmkv, m) { |
| 107 | m.doc() = "An efficient, small key-value storage framework developed by WeChat Team."; |
| 108 | |
| 109 | py::enum_<MMKVMode>(m, "MMKVMode", py::arithmetic()) |
| 110 | .value("SingleProcess", MMKVMode::MMKV_SINGLE_PROCESS) |
| 111 | .value("MultiProcess", MMKVMode::MMKV_MULTI_PROCESS) |
| 112 | .value("ReadOnly", MMKVMode::MMKV_READ_ONLY) |
| 113 | .export_values(); |
| 114 | |
| 115 | py::enum_<MMKVLogLevel>(m, "MMKVLogLevel") |
| 116 | .value("NoLog", MMKVLogLevel::MMKVLogNone) |
| 117 | .value("Debug", MMKVLogLevel::MMKVLogDebug) |
| 118 | .value("Info", MMKVLogLevel::MMKVLogInfo) |
| 119 | .value("Warning", MMKVLogLevel::MMKVLogWarning) |
| 120 | .value("Error", MMKVLogLevel::MMKVLogError) |
| 121 | .export_values(); |
| 122 | |
| 123 | py::enum_<SyncFlag>(m, "SyncFlag") |
| 124 | .value("Sync", SyncFlag::MMKV_SYNC) |
| 125 | .value("ASync", SyncFlag::MMKV_ASYNC) |
| 126 | .export_values(); |
| 127 | |
| 128 | py::enum_<MMKVRecoverStrategic>(m, "MMKVRecoverStrategic") |
| 129 | .value("OnErrorDiscard", MMKVRecoverStrategic::OnErrorDiscard) |
| 130 | .value("OnErrorRecover", MMKVRecoverStrategic::OnErrorRecover) |
| 131 | .export_values(); |
| 132 | |
| 133 | py::enum_<MMKVErrorType>(m, "MMKVErrorType") |
| 134 | .value("CRCCheckFail", MMKVErrorType::MMKVCRCCheckFail) |
| 135 | .value("FileLength", MMKVErrorType::MMKVFileLength) |
| 136 | .export_values(); |
| 137 | |
| 138 | py::class_<NameSpace, unique_ptr<NameSpace>> clsNameSpace(m, "NameSpace"); |
| 139 | |
| 140 | clsNameSpace.def("mmkvWithID", [](NameSpace &self, const string &mmapID, MMKVMode mode, const string &cryptKey, |
| 141 | const size_t expectedCapacity, bool aes256, std::optional<bool> enableKeyExpire, |
| 142 | uint32_t expiredInSeconds, bool enableCompareBeforeSet,std::optional<MMKVRecoverStrategic> recover, |
| 143 | uint32_t itemSizeLimit) { |
| 144 | auto config = pyArgsToConfig(mode, cryptKey, self.getRootDir(), expectedCapacity, aes256, |
| 145 | enableKeyExpire, expiredInSeconds, enableCompareBeforeSet, recover, itemSizeLimit); |
| 146 | return MMKV::mmkvWithID(mmapID, config); |
| 147 | }, |
| 148 | "Parameters:\n" |
| 149 | " mmapID: all instances of the same mmapID share the same data and file storage\n" |
| 150 | " mode: pass MMKVMode.MultiProcess for a multi-process MMKV\n" |
| 151 | " cryptKey: pass a non-empty string for an encrypted MMKV, 32 bytes at most\n" |
| 152 | " expectedCapacity: the file size you expected when opening or creating file\n" |
| 153 | " aes256: use AES 256 key length\n" |
| 154 | " enableKeyExpire: enable auto key expiration\n" |
| 155 | " expiredInSeconds: expiration in seconds\n" |
| 156 | " enableCompareBeforeSet: enable compare before set, if new value is the same, dont update/insert\n" |
| 157 | " recover: recover strategy on file corruption\n" |
| 158 | " itemSizeLimit: size limit for a key-value pair\n", |
| 159 | py::arg("mmapID"), py::arg("mode") = MMKV_SINGLE_PROCESS, py::arg("cryptKey") = string(), |
| 160 | py::arg("expectedCapacity") = 0, py::arg("aes256") = false, |
| 161 | py::arg("enableKeyExpire") = std::nullopt, py::arg("expiredInSeconds") = 0, |
| 162 | py::arg("enableCompareBeforeSet") = false, |
| 163 | py::arg("recover") = std::nullopt, |
nothing calls this directly
no test coverage detected