react-native-mmkv 3.3.0 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/android/CMakeLists.txt +18 -9
  2. package/android/build.gradle +6 -2
  3. package/cpp/{MMKVManagedBuffer.h → ManagedMMBuffer.h} +6 -6
  4. package/cpp/MmkvHostObject.cpp +13 -8
  5. package/cpp/MmkvHostObject.h +1 -2
  6. package/cpp/MmkvTypes.h +50 -0
  7. package/cpp/NativeMmkvModule.cpp +3 -3
  8. package/cpp/NativeMmkvModule.h +1 -8
  9. package/package.json +22 -23
  10. package/react-native-mmkv.podspec +3 -9
  11. package/react-native.config.js +9 -0
  12. package/MMKV/Core/CMakeLists.txt +0 -172
  13. package/MMKV/Core/CodedInputData.cpp +0 -252
  14. package/MMKV/Core/CodedInputData.h +0 -87
  15. package/MMKV/Core/CodedInputDataCrypt.cpp +0 -280
  16. package/MMKV/Core/CodedInputDataCrypt.h +0 -87
  17. package/MMKV/Core/CodedInputDataCrypt_OSX.cpp +0 -62
  18. package/MMKV/Core/CodedInputData_OSX.cpp +0 -92
  19. package/MMKV/Core/CodedOutputData.cpp +0 -186
  20. package/MMKV/Core/CodedOutputData.h +0 -88
  21. package/MMKV/Core/Core.xcodeproj/project.pbxproj +0 -707
  22. package/MMKV/Core/Core.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  23. package/MMKV/Core/Core.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  24. package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme +0 -67
  25. package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/MMKVWatchCore.xcscheme +0 -67
  26. package/MMKV/Core/InterProcessLock.cpp +0 -186
  27. package/MMKV/Core/InterProcessLock.h +0 -119
  28. package/MMKV/Core/InterProcessLock_Android.cpp +0 -103
  29. package/MMKV/Core/InterProcessLock_Win32.cpp +0 -108
  30. package/MMKV/Core/KeyValueHolder.cpp +0 -236
  31. package/MMKV/Core/KeyValueHolder.h +0 -122
  32. package/MMKV/Core/MMBuffer.cpp +0 -210
  33. package/MMKV/Core/MMBuffer.h +0 -111
  34. package/MMKV/Core/MMKV.cpp +0 -1702
  35. package/MMKV/Core/MMKV.h +0 -595
  36. package/MMKV/Core/MMKVLog.cpp +0 -127
  37. package/MMKV/Core/MMKVLog.h +0 -86
  38. package/MMKV/Core/MMKVLog_Android.cpp +0 -134
  39. package/MMKV/Core/MMKVMetaInfo.hpp +0 -99
  40. package/MMKV/Core/MMKVPredef.h +0 -293
  41. package/MMKV/Core/MMKV_Android.cpp +0 -261
  42. package/MMKV/Core/MMKV_IO.cpp +0 -1905
  43. package/MMKV/Core/MMKV_IO.h +0 -57
  44. package/MMKV/Core/MMKV_OSX.cpp +0 -423
  45. package/MMKV/Core/MMKV_OSX.h +0 -57
  46. package/MMKV/Core/MemoryFile.cpp +0 -603
  47. package/MMKV/Core/MemoryFile.h +0 -194
  48. package/MMKV/Core/MemoryFile_Android.cpp +0 -236
  49. package/MMKV/Core/MemoryFile_Linux.cpp +0 -125
  50. package/MMKV/Core/MemoryFile_OSX.cpp +0 -142
  51. package/MMKV/Core/MemoryFile_Win32.cpp +0 -554
  52. package/MMKV/Core/MiniPBCoder.cpp +0 -672
  53. package/MMKV/Core/MiniPBCoder.h +0 -151
  54. package/MMKV/Core/MiniPBCoder_OSX.cpp +0 -237
  55. package/MMKV/Core/PBEncodeItem.hpp +0 -104
  56. package/MMKV/Core/PBUtility.cpp +0 -61
  57. package/MMKV/Core/PBUtility.h +0 -148
  58. package/MMKV/Core/ScopedLock.hpp +0 -69
  59. package/MMKV/Core/ThreadLock.cpp +0 -75
  60. package/MMKV/Core/ThreadLock.h +0 -81
  61. package/MMKV/Core/ThreadLock_Win32.cpp +0 -89
  62. package/MMKV/Core/aes/AESCrypt.cpp +0 -273
  63. package/MMKV/Core/aes/AESCrypt.h +0 -112
  64. package/MMKV/Core/aes/openssl/openssl_aes-armv4.S +0 -1243
  65. package/MMKV/Core/aes/openssl/openssl_aes.h +0 -130
  66. package/MMKV/Core/aes/openssl/openssl_aes_core.cpp +0 -1044
  67. package/MMKV/Core/aes/openssl/openssl_aes_locl.h +0 -38
  68. package/MMKV/Core/aes/openssl/openssl_aesv8-armx.S +0 -308
  69. package/MMKV/Core/aes/openssl/openssl_arm_arch.h +0 -84
  70. package/MMKV/Core/aes/openssl/openssl_cfb128.cpp +0 -97
  71. package/MMKV/Core/aes/openssl/openssl_md32_common.h +0 -254
  72. package/MMKV/Core/aes/openssl/openssl_md5.h +0 -49
  73. package/MMKV/Core/aes/openssl/openssl_md5_dgst.cpp +0 -166
  74. package/MMKV/Core/aes/openssl/openssl_md5_locl.h +0 -75
  75. package/MMKV/Core/aes/openssl/openssl_md5_one.cpp +0 -30
  76. package/MMKV/Core/aes/openssl/openssl_opensslconf.h +0 -271
  77. package/MMKV/Core/core.vcxproj +0 -288
  78. package/MMKV/Core/core.vcxproj.filters +0 -150
  79. package/MMKV/Core/crc32/Checksum.h +0 -75
  80. package/MMKV/Core/crc32/crc32_armv8.cpp +0 -134
  81. package/MMKV/Core/crc32/zlib/CMakeLists.txt +0 -60
  82. package/MMKV/Core/crc32/zlib/crc32.cpp +0 -55
  83. package/MMKV/Core/crc32/zlib/crc32.h +0 -48
  84. package/MMKV/Core/crc32/zlib/zconf.h +0 -380
  85. package/MMKV/Core/crc32/zlib/zutil.h +0 -25
  86. package/MMKV/LICENSE.TXT +0 -193
  87. package/MMKV/README.md +0 -354
@@ -1,151 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making
3
- * MMKV available.
4
- *
5
- * Copyright (C) 2018 THL A29 Limited, a Tencent company.
6
- * All rights reserved.
7
- *
8
- * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
- * this file except in compliance with the License. You may obtain a copy of
10
- * the License at
11
- *
12
- * https://opensource.org/licenses/BSD-3-Clause
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
-
21
- #ifndef MMKV_MINIPBCODER_H
22
- #define MMKV_MINIPBCODER_H
23
- #ifdef __cplusplus
24
-
25
- #include "MMKVPredef.h"
26
-
27
- #include "MMBuffer.h"
28
- #include <cstdint>
29
- #ifdef MMKV_HAS_CPP20
30
- # include <span>
31
- # define MMKV_STRING_CONTAINER std::span<const std::string>
32
- #else
33
- # define MMKV_STRING_CONTAINER std::vector<std::string>
34
- #endif
35
-
36
-
37
- namespace mmkv {
38
-
39
- class CodedInputData;
40
- class CodedOutputData;
41
- class AESCrypt;
42
- class CodedInputDataCrypt;
43
- struct PBEncodeItem;
44
-
45
- class MiniPBCoder {
46
- const MMBuffer *m_inputBuffer = nullptr;
47
- CodedInputData *m_inputData = nullptr;
48
- CodedInputDataCrypt *m_inputDataDecrpt = nullptr;
49
-
50
- MMBuffer *m_outputBuffer = nullptr;
51
- CodedOutputData *m_outputData = nullptr;
52
- std::vector<PBEncodeItem> *m_encodeItems = nullptr;
53
-
54
- MiniPBCoder();
55
- explicit MiniPBCoder(const MMBuffer *inputBuffer, AESCrypt *crypter = nullptr);
56
- ~MiniPBCoder();
57
-
58
- void writeRootObject();
59
-
60
- size_t prepareObjectForEncode(const MMKVVector &vec);
61
- size_t prepareObjectForEncode(const MMBuffer &buffer);
62
-
63
- template <typename T>
64
- MMBuffer getEncodeData(const T &obj) {
65
- size_t index = prepareObjectForEncode(obj);
66
- return writePreparedItems(index);
67
- }
68
-
69
- MMBuffer writePreparedItems(size_t index);
70
-
71
- void decodeOneMap(MMKVMap &dic, size_t position, bool greedy);
72
- #ifndef MMKV_DISABLE_CRYPT
73
- void decodeOneMap(MMKVMapCrypt &dic, size_t position, bool greedy);
74
- #endif
75
-
76
- #ifndef MMKV_APPLE
77
- size_t prepareObjectForEncode(const std::string &str);
78
- size_t prepareObjectForEncode(const MMKV_STRING_CONTAINER &vector);
79
- std::vector<std::string> decodeOneVector();
80
- #ifdef MMKV_HAS_CPP20
81
- size_t prepareObjectForEncode(const std::span<const int32_t> &vec);
82
- size_t prepareObjectForEncode(const std::span<const uint32_t> &vec);
83
- size_t prepareObjectForEncode(const std::span<const int64_t> &vec);
84
- size_t prepareObjectForEncode(const std::span<const uint64_t> &vec);
85
-
86
- bool decodeOneVector(std::vector<bool> &result);
87
- bool decodeOneVector(std::vector<int32_t> &result);
88
- bool decodeOneVector(std::vector<uint32_t> &result);
89
- bool decodeOneVector(std::vector<int64_t> &result);
90
- bool decodeOneVector(std::vector<uint64_t> &result);
91
- bool decodeOneVector(std::vector<float> &result);
92
- bool decodeOneVector(std::vector<double> &result);
93
-
94
- // special case for fixed size types
95
- MMBuffer getEncodeData(const std::vector<bool> &obj);
96
- MMBuffer getEncodeData(const std::span<const float> &obj);
97
- MMBuffer getEncodeData(const std::span<const double> &obj);
98
- #endif // MMKV_HAS_CPP20
99
- #else
100
- // NSString, NSData, NSDate
101
- size_t prepareObjectForEncode(__unsafe_unretained NSObject *obj);
102
- #endif // MMKV_APPLE
103
-
104
- public:
105
- template <typename T>
106
- static MMBuffer encodeDataWithObject(const T &obj) {
107
- MiniPBCoder pbCoder;
108
- return pbCoder.getEncodeData(obj);
109
- }
110
-
111
- // opt encoding a single MMBuffer
112
- static MMBuffer encodeDataWithObject(const MMBuffer &obj);
113
-
114
- // return empty result if there's any error
115
- static void decodeMap(MMKVMap &dic, const MMBuffer &oData, size_t position = 0);
116
-
117
- // decode as much data as possible before any error happens
118
- static void greedyDecodeMap(MMKVMap &dic, const MMBuffer &oData, size_t position = 0);
119
-
120
- #ifndef MMKV_DISABLE_CRYPT
121
- // return empty result if there's any error
122
- static void decodeMap(MMKVMapCrypt &dic, const MMBuffer &oData, AESCrypt *crypter, size_t position = 0);
123
-
124
- // decode as much data as possible before any error happens
125
- static void greedyDecodeMap(MMKVMapCrypt &dic, const MMBuffer &oData, AESCrypt *crypter, size_t position = 0);
126
- #endif // MMKV_DISABLE_CRYPT
127
-
128
- #ifndef MMKV_APPLE
129
- static std::vector<std::string> decodeVector(const MMBuffer &oData);
130
-
131
- template <typename T>
132
- static bool decodeVector(const MMBuffer &oData, std::vector<T> &result) {
133
- MiniPBCoder oCoder(&oData);
134
- return oCoder.decodeOneVector(result);
135
- }
136
- #else
137
- // NSString, NSData, NSDate
138
- static NSObject *decodeObject(const MMBuffer &oData, Class cls);
139
-
140
- static bool isCompatibleClass(Class cls);
141
- #endif
142
-
143
- // just forbid it for possibly misuse
144
- explicit MiniPBCoder(const MiniPBCoder &other) = delete;
145
- MiniPBCoder &operator=(const MiniPBCoder &other) = delete;
146
- };
147
-
148
- } // namespace mmkv
149
-
150
- #endif
151
- #endif //MMKV_MINIPBCODER_H
@@ -1,237 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making
3
- * MMKV available.
4
- *
5
- * Copyright (C) 2019 THL A29 Limited, a Tencent company.
6
- * All rights reserved.
7
- *
8
- * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
- * this file except in compliance with the License. You may obtain a copy of
10
- * the License at
11
- *
12
- * https://opensource.org/licenses/BSD-3-Clause
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
-
21
- #include "MiniPBCoder.h"
22
- #include "MMKVLog.h"
23
-
24
- #ifdef MMKV_APPLE
25
-
26
- # include "CodedInputData.h"
27
- # include "CodedInputDataCrypt.h"
28
- # include "CodedOutputData.h"
29
- # include "MMBuffer.h"
30
- # include "PBEncodeItem.hpp"
31
- # include "PBUtility.h"
32
- # include <string>
33
- # include <vector>
34
-
35
- # if __has_feature(objc_arc)
36
- # error This file must be compiled with MRC. Use -fno-objc-arc flag.
37
- # endif
38
-
39
- using namespace std;
40
-
41
- namespace mmkv {
42
-
43
- size_t MiniPBCoder::prepareObjectForEncode(__unsafe_unretained NSObject *obj) {
44
- if (!obj) {
45
- return m_encodeItems->size();
46
- }
47
- m_encodeItems->push_back(PBEncodeItem());
48
- PBEncodeItem *encodeItem = &(m_encodeItems->back());
49
- size_t index = m_encodeItems->size() - 1;
50
-
51
- if ([obj isKindOfClass:[NSString class]]) {
52
- NSString *str = (NSString *) obj;
53
- encodeItem->type = PBEncodeItemType_NSString;
54
- NSData *buffer = [[str dataUsingEncoding:NSUTF8StringEncoding] retain];
55
- encodeItem->value.tmpObjectValue = (__bridge void *) buffer;
56
- encodeItem->valueSize = static_cast<uint32_t>(buffer.length);
57
- } else if ([obj isKindOfClass:[NSDate class]]) {
58
- NSDate *oDate = (NSDate *) obj;
59
- encodeItem->type = PBEncodeItemType_NSDate;
60
- encodeItem->value.objectValue = (__bridge void *) oDate;
61
- encodeItem->valueSize = pbDoubleSize();
62
- encodeItem->compiledSize = encodeItem->valueSize;
63
- return index; // double has fixed compilesize
64
- } else if ([obj isKindOfClass:[NSData class]]) {
65
- NSData *oData = (NSData *) obj;
66
- encodeItem->type = PBEncodeItemType_NSData;
67
- encodeItem->value.objectValue = (__bridge void *) oData;
68
- encodeItem->valueSize = static_cast<uint32_t>(oData.length);
69
- } else {
70
- m_encodeItems->pop_back();
71
- MMKVError("%@ not recognized", NSStringFromClass(obj.class));
72
- return m_encodeItems->size();
73
- }
74
- encodeItem->compiledSize = pbRawVarint32Size(encodeItem->valueSize) + encodeItem->valueSize;
75
-
76
- return index;
77
- }
78
-
79
- void MiniPBCoder::decodeOneMap(MMKVMap &dic, size_t position, bool greedy) {
80
- auto block = [position, this](MMKVMap &dictionary) {
81
- if (position) {
82
- m_inputData->seek(position);
83
- } else {
84
- m_inputData->readInt32();
85
- }
86
- while (!m_inputData->isAtEnd()) {
87
- KeyValueHolder kvHolder;
88
- const auto &key = m_inputData->readString(kvHolder);
89
- if (key.length > 0) {
90
- m_inputData->readData(kvHolder);
91
- auto itr = dictionary.find(key);
92
- if (itr != dictionary.end()) {
93
- if (kvHolder.valueSize > 0) {
94
- itr->second = std::move(kvHolder);
95
- } else {
96
- auto oldKey = itr->first;
97
- dictionary.erase(itr);
98
- [oldKey release];
99
- }
100
- } else {
101
- if (kvHolder.valueSize > 0) {
102
- dictionary.emplace(key, std::move(kvHolder));
103
- [key retain];
104
- }
105
- }
106
- }
107
- }
108
- };
109
-
110
- if (greedy) {
111
- try {
112
- block(dic);
113
- } catch (std::exception &exception) {
114
- MMKVError("%s", exception.what());
115
- } catch (...) {
116
- MMKVError("decode fail");
117
- }
118
- } else {
119
- try {
120
- MMKVMap tmpDic;
121
- block(tmpDic);
122
- dic.swap(tmpDic);
123
- for (auto &pair : tmpDic) {
124
- [pair.first release];
125
- }
126
- } catch (std::exception &exception) {
127
- MMKVError("%s", exception.what());
128
- } catch (...) {
129
- MMKVError("decode fail");
130
- }
131
- }
132
- }
133
-
134
- # ifndef MMKV_DISABLE_CRYPT
135
-
136
- void MiniPBCoder::decodeOneMap(MMKVMapCrypt &dic, size_t position, bool greedy) {
137
- auto block = [position, this](MMKVMapCrypt &dictionary) {
138
- if (position) {
139
- m_inputDataDecrpt->seek(position);
140
- } else {
141
- m_inputDataDecrpt->readInt32();
142
- }
143
- while (!m_inputDataDecrpt->isAtEnd()) {
144
- KeyValueHolderCrypt kvHolder;
145
- const auto &key = m_inputDataDecrpt->readString(kvHolder);
146
- if (key.length > 0) {
147
- m_inputDataDecrpt->readData(kvHolder);
148
- auto itr = dictionary.find(key);
149
- if (itr != dictionary.end()) {
150
- if (kvHolder.realValueSize() > 0) {
151
- itr->second = std::move(kvHolder);
152
- } else {
153
- auto oldKey = itr->first;
154
- dictionary.erase(itr);
155
- [oldKey release];
156
- }
157
- } else {
158
- if (kvHolder.realValueSize() > 0) {
159
- dictionary.emplace(key, std::move(kvHolder));
160
- [key retain];
161
- }
162
- }
163
- }
164
- }
165
- };
166
-
167
- if (greedy) {
168
- try {
169
- block(dic);
170
- } catch (std::exception &exception) {
171
- MMKVError("%s", exception.what());
172
- } catch (...) {
173
- MMKVError("decode fail");
174
- }
175
- } else {
176
- try {
177
- MMKVMapCrypt tmpDic;
178
- block(tmpDic);
179
- dic.swap(tmpDic);
180
- for (auto &pair : tmpDic) {
181
- [pair.first release];
182
- }
183
- } catch (std::exception &exception) {
184
- MMKVError("%s", exception.what());
185
- } catch (...) {
186
- MMKVError("decode fail");
187
- }
188
- }
189
- }
190
-
191
- # endif // MMKV_DISABLE_CRYPT
192
-
193
- NSObject *MiniPBCoder::decodeObject(const MMBuffer &oData, Class cls) {
194
- if (!cls || oData.length() == 0) {
195
- return nil;
196
- }
197
- CodedInputData input(oData.getPtr(), oData.length());
198
- if (cls == [NSString class]) {
199
- return input.readString();
200
- } else if (cls == [NSMutableString class]) {
201
- return [NSMutableString stringWithString:input.readString()];
202
- } else if (cls == [NSData class]) {
203
- return input.readNSData();
204
- } else if (cls == [NSMutableData class]) {
205
- return [NSMutableData dataWithData:input.readNSData()];
206
- } else if (cls == [NSDate class]) {
207
- return [NSDate dateWithTimeIntervalSince1970:input.readDouble()];
208
- } else {
209
- MMKVError("%@ not recognized", NSStringFromClass(cls));
210
- }
211
-
212
- return nil;
213
- }
214
-
215
- bool MiniPBCoder::isCompatibleClass(Class cls) {
216
- if (cls == [NSString class]) {
217
- return true;
218
- }
219
- if (cls == [NSMutableString class]) {
220
- return true;
221
- }
222
- if (cls == [NSData class]) {
223
- return true;
224
- }
225
- if (cls == [NSMutableData class]) {
226
- return true;
227
- }
228
- if (cls == [NSDate class]) {
229
- return true;
230
- }
231
-
232
- return false;
233
- }
234
-
235
- } // namespace mmkv
236
-
237
- #endif // MMKV_APPLE
@@ -1,104 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making
3
- * MMKV available.
4
- *
5
- * Copyright (C) 2018 THL A29 Limited, a Tencent company.
6
- * All rights reserved.
7
- *
8
- * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
- * this file except in compliance with the License. You may obtain a copy of
10
- * the License at
11
- *
12
- * https://opensource.org/licenses/BSD-3-Clause
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
-
21
- #ifndef MMKV_PBENCODEITEM_HPP
22
- #define MMKV_PBENCODEITEM_HPP
23
- #ifdef __cplusplus
24
-
25
- #include "MMKVPredef.h"
26
-
27
- #include "MMBuffer.h"
28
- #include <cstdint>
29
- #include <memory.h>
30
-
31
- namespace mmkv {
32
-
33
- enum PBEncodeItemType {
34
- PBEncodeItemType_None,
35
- PBEncodeItemType_Data,
36
- PBEncodeItemType_Container,
37
- #ifndef MMKV_APPLE
38
- PBEncodeItemType_String,
39
- #ifdef MMKV_HAS_CPP20
40
- PBEncodeItemType_Int32,
41
- PBEncodeItemType_UInt32,
42
- PBEncodeItemType_Int64,
43
- PBEncodeItemType_UInt64,
44
- // PBEncodeItemType_Bool,
45
- // PBEncodeItemType_Float,
46
- // PBEncodeItemType_Double,
47
- #endif // MMKV_HAS_CPP20
48
- #else
49
- PBEncodeItemType_NSString,
50
- PBEncodeItemType_NSData,
51
- PBEncodeItemType_NSDate,
52
- #endif
53
- };
54
-
55
- struct PBEncodeItem {
56
- PBEncodeItemType type;
57
- uint32_t compiledSize;
58
- uint32_t valueSize;
59
- union {
60
- const MMBuffer *bufferValue;
61
- #ifndef MMKV_APPLE
62
- #ifdef MMKV_HAS_CPP20
63
- // bool boolValue;
64
- int32_t int32Value;
65
- int64_t int64Value;
66
- uint32_t uint32Value;
67
- uint64_t uint64Value;
68
- #endif // MMKV_HAS_CPP20
69
- // float floatValue;
70
- // double doubleValue;
71
- const std::string *strValue;
72
- #else
73
- void *objectValue;
74
- void *tmpObjectValue; // this object should be released on dealloc
75
- #endif
76
- } value;
77
-
78
- PBEncodeItem() : type(PBEncodeItemType_None), compiledSize(0), valueSize(0) { memset(&value, 0, sizeof(value)); }
79
-
80
- #ifndef MMKV_APPLE
81
- // opt std::vector.push_back() on slow_path
82
- PBEncodeItem(PBEncodeItem &&other) = default;
83
- #else
84
- // opt std::vector.push_back() on slow_path
85
- PBEncodeItem(PBEncodeItem &&other)
86
- : type(other.type), compiledSize(other.compiledSize), valueSize(other.valueSize), value(other.value) {
87
- // omit unnecessary CFRetain() & CFRelease()
88
- other.type = PBEncodeItemType_None;
89
- }
90
-
91
- ~PBEncodeItem() {
92
- if (type == PBEncodeItemType_NSString) {
93
- if (value.tmpObjectValue) {
94
- CFRelease(value.tmpObjectValue);
95
- }
96
- }
97
- }
98
- #endif // MMKV_APPLE
99
- };
100
-
101
- } // namespace mmkv
102
-
103
- #endif
104
- #endif //MMKV_PBENCODEITEM_HPP
@@ -1,61 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making
3
- * MMKV available.
4
- *
5
- * Copyright (C) 2018 THL A29 Limited, a Tencent company.
6
- * All rights reserved.
7
- *
8
- * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
- * this file except in compliance with the License. You may obtain a copy of
10
- * the License at
11
- *
12
- * https://opensource.org/licenses/BSD-3-Clause
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
- #include "MMBuffer.h"
21
- #include "PBUtility.h"
22
-
23
- namespace mmkv {
24
-
25
- uint32_t pbRawVarint32Size(uint32_t value) {
26
- if ((value & (0xffffffff << 7)) == 0) {
27
- return 1;
28
- } else if ((value & (0xffffffff << 14)) == 0) {
29
- return 2;
30
- } else if ((value & (0xffffffff << 21)) == 0) {
31
- return 3;
32
- } else if ((value & (0xffffffff << 28)) == 0) {
33
- return 4;
34
- }
35
- return 5;
36
- }
37
-
38
- uint32_t pbUInt64Size(uint64_t value) {
39
- if ((value & (0xffffffffffffffffL << 7)) == 0) {
40
- return 1;
41
- } else if ((value & (0xffffffffffffffffL << 14)) == 0) {
42
- return 2;
43
- } else if ((value & (0xffffffffffffffffL << 21)) == 0) {
44
- return 3;
45
- } else if ((value & (0xffffffffffffffffL << 28)) == 0) {
46
- return 4;
47
- } else if ((value & (0xffffffffffffffffL << 35)) == 0) {
48
- return 5;
49
- } else if ((value & (0xffffffffffffffffL << 42)) == 0) {
50
- return 6;
51
- } else if ((value & (0xffffffffffffffffL << 49)) == 0) {
52
- return 7;
53
- } else if ((value & (0xffffffffffffffffL << 56)) == 0) {
54
- return 8;
55
- } else if ((value & (0xffffffffffffffffL << 63)) == 0) {
56
- return 9;
57
- }
58
- return 10;
59
- }
60
-
61
- } // namespace mmkv
@@ -1,148 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making
3
- * MMKV available.
4
- *
5
- * Copyright (C) 2018 THL A29 Limited, a Tencent company.
6
- * All rights reserved.
7
- *
8
- * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
- * this file except in compliance with the License. You may obtain a copy of
10
- * the License at
11
- *
12
- * https://opensource.org/licenses/BSD-3-Clause
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
-
21
- #ifndef MMKV_PBUTILITY_H
22
- #define MMKV_PBUTILITY_H
23
- #ifdef __cplusplus
24
-
25
- #include "MMKVPredef.h"
26
-
27
- #include <cstdint>
28
-
29
- namespace mmkv {
30
-
31
- template <typename T, typename P>
32
- union Converter {
33
- static_assert(sizeof(T) == sizeof(P), "size not match");
34
- T first;
35
- P second;
36
- };
37
-
38
- static inline int64_t Float64ToInt64(double v) {
39
- Converter<double, int64_t> converter;
40
- converter.first = v;
41
- return converter.second;
42
- }
43
-
44
- static inline int32_t Float32ToInt32(float v) {
45
- Converter<float, int32_t> converter;
46
- converter.first = v;
47
- return converter.second;
48
- }
49
-
50
- static inline double Int64ToFloat64(int64_t v) {
51
- Converter<double, int64_t> converter;
52
- converter.second = v;
53
- return converter.first;
54
- }
55
-
56
- static inline float Int32ToFloat32(int32_t v) {
57
- Converter<float, int32_t> converter;
58
- converter.second = v;
59
- return converter.first;
60
- }
61
-
62
- static inline uint64_t Int64ToUInt64(int64_t v) {
63
- Converter<int64_t, uint64_t> converter;
64
- converter.first = v;
65
- return converter.second;
66
- }
67
-
68
- static inline int64_t UInt64ToInt64(uint64_t v) {
69
- Converter<int64_t, uint64_t> converter;
70
- converter.second = v;
71
- return converter.first;
72
- }
73
-
74
- static inline uint32_t Int32ToUInt32(int32_t v) {
75
- Converter<int32_t, uint32_t> converter;
76
- converter.first = v;
77
- return converter.second;
78
- }
79
-
80
- static inline int32_t UInt32ToInt32(uint32_t v) {
81
- Converter<int32_t, uint32_t> converter;
82
- converter.second = v;
83
- return converter.first;
84
- }
85
-
86
- static inline int32_t logicalRightShift32(int32_t value, uint32_t spaces) {
87
- return UInt32ToInt32((Int32ToUInt32(value) >> spaces));
88
- }
89
-
90
- static inline int64_t logicalRightShift64(int64_t value, uint32_t spaces) {
91
- return UInt64ToInt64((Int64ToUInt64(value) >> spaces));
92
- }
93
-
94
- constexpr uint32_t LittleEdian32Size = 4;
95
-
96
- constexpr uint32_t pbFloatSize() {
97
- return LittleEdian32Size;
98
- }
99
-
100
- constexpr uint32_t pbFixed32Size() {
101
- return LittleEdian32Size;
102
- }
103
-
104
- constexpr uint32_t LittleEdian64Size = 8;
105
-
106
- constexpr uint32_t pbDoubleSize() {
107
- return LittleEdian64Size;
108
- }
109
-
110
- constexpr uint32_t pbBoolSize() {
111
- return 1;
112
- }
113
-
114
- extern uint32_t pbRawVarint32Size(uint32_t value);
115
-
116
- static inline uint32_t pbRawVarint32Size(int32_t value) {
117
- return pbRawVarint32Size(Int32ToUInt32(value));
118
- }
119
-
120
- extern uint32_t pbUInt64Size(uint64_t value);
121
-
122
- static inline uint32_t pbInt64Size(int64_t value) {
123
- return pbUInt64Size(Int64ToUInt64(value));
124
- }
125
-
126
- static inline uint32_t pbInt32Size(int32_t value) {
127
- if (value >= 0) {
128
- return pbRawVarint32Size(value);
129
- } else {
130
- return 10;
131
- }
132
- }
133
-
134
- static inline uint32_t pbUInt32Size(uint32_t value) {
135
- return pbRawVarint32Size(value);
136
- }
137
-
138
- static inline uint32_t pbMMBufferSize(const MMBuffer &data) {
139
- auto valueLength = static_cast<uint32_t>(data.length());
140
- return valueLength + pbUInt32Size(valueLength);
141
- }
142
-
143
- constexpr uint32_t Fixed32Size = pbFixed32Size();
144
-
145
- } // namespace mmkv
146
-
147
- #endif
148
- #endif //MMKV_PBUTILITY_H