react-native-mmkv 3.2.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.
- package/android/CMakeLists.txt +18 -9
- package/android/build.gradle +6 -2
- package/cpp/{MMKVManagedBuffer.h → ManagedMMBuffer.h} +6 -6
- package/cpp/MmkvHostObject.cpp +22 -17
- package/cpp/MmkvHostObject.h +1 -2
- package/cpp/MmkvTypes.h +50 -0
- package/cpp/NativeMmkvModule.cpp +3 -3
- package/cpp/NativeMmkvModule.h +1 -8
- package/lib/commonjs/MMKV.js.map +1 -1
- package/lib/commonjs/Types.js.map +1 -1
- package/lib/commonjs/createMMKV.web.js +1 -1
- package/lib/commonjs/createMMKV.web.js.map +1 -1
- package/lib/module/MMKV.js.map +1 -1
- package/lib/module/Types.js.map +1 -1
- package/lib/module/createMMKV.web.js +1 -1
- package/lib/module/createMMKV.web.js.map +1 -1
- package/lib/typescript/src/MMKV.d.ts +1 -1
- package/lib/typescript/src/MMKV.d.ts.map +1 -1
- package/lib/typescript/src/Types.d.ts +7 -1
- package/lib/typescript/src/Types.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +1 -1
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/package.json +22 -27
- package/react-native-mmkv.podspec +4 -10
- package/react-native.config.js +9 -0
- package/src/MMKV.ts +1 -1
- package/src/Types.ts +7 -1
- package/src/createMMKV.web.ts +1 -1
- package/src/hooks.ts +1 -1
- package/MMKV/Core/CMakeLists.txt +0 -172
- package/MMKV/Core/CodedInputData.cpp +0 -252
- package/MMKV/Core/CodedInputData.h +0 -87
- package/MMKV/Core/CodedInputDataCrypt.cpp +0 -280
- package/MMKV/Core/CodedInputDataCrypt.h +0 -87
- package/MMKV/Core/CodedInputDataCrypt_OSX.cpp +0 -62
- package/MMKV/Core/CodedInputData_OSX.cpp +0 -92
- package/MMKV/Core/CodedOutputData.cpp +0 -186
- package/MMKV/Core/CodedOutputData.h +0 -88
- package/MMKV/Core/Core.xcodeproj/project.pbxproj +0 -707
- package/MMKV/Core/Core.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/MMKV/Core/Core.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme +0 -67
- package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/MMKVWatchCore.xcscheme +0 -67
- package/MMKV/Core/InterProcessLock.cpp +0 -186
- package/MMKV/Core/InterProcessLock.h +0 -119
- package/MMKV/Core/InterProcessLock_Android.cpp +0 -103
- package/MMKV/Core/InterProcessLock_Win32.cpp +0 -108
- package/MMKV/Core/KeyValueHolder.cpp +0 -236
- package/MMKV/Core/KeyValueHolder.h +0 -122
- package/MMKV/Core/MMBuffer.cpp +0 -210
- package/MMKV/Core/MMBuffer.h +0 -111
- package/MMKV/Core/MMKV.cpp +0 -1702
- package/MMKV/Core/MMKV.h +0 -595
- package/MMKV/Core/MMKVLog.cpp +0 -127
- package/MMKV/Core/MMKVLog.h +0 -86
- package/MMKV/Core/MMKVLog_Android.cpp +0 -134
- package/MMKV/Core/MMKVMetaInfo.hpp +0 -99
- package/MMKV/Core/MMKVPredef.h +0 -293
- package/MMKV/Core/MMKV_Android.cpp +0 -261
- package/MMKV/Core/MMKV_IO.cpp +0 -1905
- package/MMKV/Core/MMKV_IO.h +0 -57
- package/MMKV/Core/MMKV_OSX.cpp +0 -423
- package/MMKV/Core/MMKV_OSX.h +0 -57
- package/MMKV/Core/MemoryFile.cpp +0 -603
- package/MMKV/Core/MemoryFile.h +0 -194
- package/MMKV/Core/MemoryFile_Android.cpp +0 -236
- package/MMKV/Core/MemoryFile_Linux.cpp +0 -125
- package/MMKV/Core/MemoryFile_OSX.cpp +0 -142
- package/MMKV/Core/MemoryFile_Win32.cpp +0 -554
- package/MMKV/Core/MiniPBCoder.cpp +0 -672
- package/MMKV/Core/MiniPBCoder.h +0 -151
- package/MMKV/Core/MiniPBCoder_OSX.cpp +0 -237
- package/MMKV/Core/PBEncodeItem.hpp +0 -104
- package/MMKV/Core/PBUtility.cpp +0 -61
- package/MMKV/Core/PBUtility.h +0 -148
- package/MMKV/Core/ScopedLock.hpp +0 -69
- package/MMKV/Core/ThreadLock.cpp +0 -75
- package/MMKV/Core/ThreadLock.h +0 -81
- package/MMKV/Core/ThreadLock_Win32.cpp +0 -89
- package/MMKV/Core/aes/AESCrypt.cpp +0 -273
- package/MMKV/Core/aes/AESCrypt.h +0 -112
- package/MMKV/Core/aes/openssl/openssl_aes-armv4.S +0 -1243
- package/MMKV/Core/aes/openssl/openssl_aes.h +0 -130
- package/MMKV/Core/aes/openssl/openssl_aes_core.cpp +0 -1044
- package/MMKV/Core/aes/openssl/openssl_aes_locl.h +0 -38
- package/MMKV/Core/aes/openssl/openssl_aesv8-armx.S +0 -308
- package/MMKV/Core/aes/openssl/openssl_arm_arch.h +0 -84
- package/MMKV/Core/aes/openssl/openssl_cfb128.cpp +0 -97
- package/MMKV/Core/aes/openssl/openssl_md32_common.h +0 -254
- package/MMKV/Core/aes/openssl/openssl_md5.h +0 -49
- package/MMKV/Core/aes/openssl/openssl_md5_dgst.cpp +0 -166
- package/MMKV/Core/aes/openssl/openssl_md5_locl.h +0 -75
- package/MMKV/Core/aes/openssl/openssl_md5_one.cpp +0 -30
- package/MMKV/Core/aes/openssl/openssl_opensslconf.h +0 -271
- package/MMKV/Core/core.vcxproj +0 -288
- package/MMKV/Core/core.vcxproj.filters +0 -150
- package/MMKV/Core/crc32/Checksum.h +0 -75
- package/MMKV/Core/crc32/crc32_armv8.cpp +0 -134
- package/MMKV/Core/crc32/zlib/CMakeLists.txt +0 -60
- package/MMKV/Core/crc32/zlib/crc32.cpp +0 -55
- package/MMKV/Core/crc32/zlib/crc32.h +0 -48
- package/MMKV/Core/crc32/zlib/zconf.h +0 -380
- package/MMKV/Core/crc32/zlib/zutil.h +0 -25
- package/MMKV/README.md +0 -354
package/MMKV/Core/MMKVLog.cpp
DELETED
|
@@ -1,127 +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 "MMKVLog.h"
|
|
22
|
-
|
|
23
|
-
MMKV_NAMESPACE_BEGIN
|
|
24
|
-
|
|
25
|
-
#ifdef MMKV_DEBUG
|
|
26
|
-
MMKVLogLevel g_currentLogLevel = MMKVLogDebug;
|
|
27
|
-
#else
|
|
28
|
-
MMKVLogLevel g_currentLogLevel = MMKVLogInfo;
|
|
29
|
-
#endif
|
|
30
|
-
|
|
31
|
-
mmkv::LogHandler g_logHandler = nullptr;
|
|
32
|
-
|
|
33
|
-
#ifndef __FILE_NAME__
|
|
34
|
-
const char *_getFileName(const char *path) {
|
|
35
|
-
const char *ptr = strrchr(path, '/');
|
|
36
|
-
if (!ptr) {
|
|
37
|
-
ptr = strrchr(path, '\\');
|
|
38
|
-
}
|
|
39
|
-
if (ptr) {
|
|
40
|
-
return ptr + 1;
|
|
41
|
-
} else {
|
|
42
|
-
return path;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
#endif
|
|
46
|
-
|
|
47
|
-
MMKV_NAMESPACE_END
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
#ifdef ENABLE_MMKV_LOG
|
|
51
|
-
# include <cstdarg>
|
|
52
|
-
# include <string>
|
|
53
|
-
|
|
54
|
-
using namespace mmkv;
|
|
55
|
-
|
|
56
|
-
# ifndef MMKV_ANDROID
|
|
57
|
-
|
|
58
|
-
static const char *MMKVLogLevelDesc(MMKVLogLevel level) {
|
|
59
|
-
switch (level) {
|
|
60
|
-
case MMKVLogDebug:
|
|
61
|
-
return "D";
|
|
62
|
-
case MMKVLogInfo:
|
|
63
|
-
return "I";
|
|
64
|
-
case MMKVLogWarning:
|
|
65
|
-
return "W";
|
|
66
|
-
case MMKVLogError:
|
|
67
|
-
return "E";
|
|
68
|
-
default:
|
|
69
|
-
return "N";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
# ifdef MMKV_APPLE
|
|
74
|
-
|
|
75
|
-
void _MMKVLogWithLevel(MMKVLogLevel level, const char *filename, const char *func, int line, const char *format, ...) {
|
|
76
|
-
if (level >= g_currentLogLevel) {
|
|
77
|
-
NSString *nsFormat = [NSString stringWithUTF8String:format];
|
|
78
|
-
va_list argList;
|
|
79
|
-
va_start(argList, format);
|
|
80
|
-
NSString *message = [[NSString alloc] initWithFormat:nsFormat arguments:argList];
|
|
81
|
-
va_end(argList);
|
|
82
|
-
|
|
83
|
-
if (g_logHandler) {
|
|
84
|
-
g_logHandler(level, filename, line, func, message);
|
|
85
|
-
} else {
|
|
86
|
-
NSLog(@"[%s] <%s:%d::%s> %@", MMKVLogLevelDesc(level), filename, line, func, message);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
# else
|
|
92
|
-
|
|
93
|
-
void _MMKVLogWithLevel(MMKVLogLevel level, const char *filename, const char *func, int line, const char *format, ...) {
|
|
94
|
-
if (level >= g_currentLogLevel) {
|
|
95
|
-
std::string message;
|
|
96
|
-
char buffer[16];
|
|
97
|
-
|
|
98
|
-
va_list args;
|
|
99
|
-
va_start(args, format);
|
|
100
|
-
auto length = std::vsnprintf(buffer, sizeof(buffer), format, args);
|
|
101
|
-
va_end(args);
|
|
102
|
-
|
|
103
|
-
if (length < 0) { // something wrong
|
|
104
|
-
message = {};
|
|
105
|
-
} else if (length < sizeof(buffer)) {
|
|
106
|
-
message = std::string(buffer, static_cast<unsigned long>(length));
|
|
107
|
-
} else {
|
|
108
|
-
message.resize(static_cast<unsigned long>(length), '\0');
|
|
109
|
-
va_start(args, format);
|
|
110
|
-
std::vsnprintf(const_cast<char *>(message.data()), static_cast<size_t>(length) + 1, format, args);
|
|
111
|
-
va_end(args);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (g_logHandler) {
|
|
115
|
-
g_logHandler(level, filename, line, func, message);
|
|
116
|
-
} else {
|
|
117
|
-
printf("[%s] <%s:%d::%s> %s\n", MMKVLogLevelDesc(level), filename, line, func, message.c_str());
|
|
118
|
-
//fflush(stdout);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
# endif // MMKV_APPLE
|
|
124
|
-
|
|
125
|
-
# endif // MMKV_ANDROID
|
|
126
|
-
|
|
127
|
-
#endif // ENABLE_MMKV_LOG
|
package/MMKV/Core/MMKVLog.h
DELETED
|
@@ -1,86 +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_MMKVLOG_H
|
|
22
|
-
#define MMKV_MMKVLOG_H
|
|
23
|
-
#ifdef __cplusplus
|
|
24
|
-
|
|
25
|
-
#include "MMKVPredef.h"
|
|
26
|
-
|
|
27
|
-
#include <cerrno>
|
|
28
|
-
#include <cstdint>
|
|
29
|
-
#include <cstring>
|
|
30
|
-
|
|
31
|
-
void _MMKVLogWithLevel(
|
|
32
|
-
MMKV_NAMESPACE_PREFIX::MMKVLogLevel level, const char *filename, const char *func, int line, const char *format, ...);
|
|
33
|
-
|
|
34
|
-
MMKV_NAMESPACE_BEGIN
|
|
35
|
-
|
|
36
|
-
extern MMKVLogLevel g_currentLogLevel;
|
|
37
|
-
extern mmkv::LogHandler g_logHandler;
|
|
38
|
-
|
|
39
|
-
// enable logging
|
|
40
|
-
#define ENABLE_MMKV_LOG
|
|
41
|
-
|
|
42
|
-
#ifdef ENABLE_MMKV_LOG
|
|
43
|
-
|
|
44
|
-
# ifdef __FILE_NAME__
|
|
45
|
-
# define __MMKV_FILE_NAME__ __FILE_NAME__
|
|
46
|
-
# else
|
|
47
|
-
const char *_getFileName(const char *path);
|
|
48
|
-
# define __MMKV_FILE_NAME__ MMKV_NAMESPACE_PREFIX::_getFileName(__FILE__)
|
|
49
|
-
# endif
|
|
50
|
-
|
|
51
|
-
# define MMKVError(format, ...) \
|
|
52
|
-
_MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogError, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
|
|
53
|
-
##__VA_ARGS__)
|
|
54
|
-
# define MMKVWarning(format, ...) \
|
|
55
|
-
_MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogWarning, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
|
|
56
|
-
##__VA_ARGS__)
|
|
57
|
-
# define MMKVInfo(format, ...) \
|
|
58
|
-
_MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogInfo, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
|
|
59
|
-
##__VA_ARGS__)
|
|
60
|
-
|
|
61
|
-
# ifdef MMKV_DEBUG
|
|
62
|
-
# define MMKVDebug(format, ...) \
|
|
63
|
-
_MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogDebug, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
|
|
64
|
-
##__VA_ARGS__)
|
|
65
|
-
# else
|
|
66
|
-
# define MMKVDebug(format, ...) \
|
|
67
|
-
{}
|
|
68
|
-
# endif
|
|
69
|
-
|
|
70
|
-
#else
|
|
71
|
-
|
|
72
|
-
# define MMKVError(format, ...) \
|
|
73
|
-
{}
|
|
74
|
-
# define MMKVWarning(format, ...) \
|
|
75
|
-
{}
|
|
76
|
-
# define MMKVInfo(format, ...) \
|
|
77
|
-
{}
|
|
78
|
-
# define MMKVDebug(format, ...) \
|
|
79
|
-
{}
|
|
80
|
-
|
|
81
|
-
#endif
|
|
82
|
-
|
|
83
|
-
MMKV_NAMESPACE_END
|
|
84
|
-
|
|
85
|
-
#endif
|
|
86
|
-
#endif //MMKV_MMKVLOG_H
|
|
@@ -1,134 +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 "MMKVLog.h"
|
|
22
|
-
|
|
23
|
-
#ifdef ENABLE_MMKV_LOG
|
|
24
|
-
# ifdef MMKV_OHOS
|
|
25
|
-
# include <hilog/log.h>
|
|
26
|
-
# include <cstdarg>
|
|
27
|
-
# include <string>
|
|
28
|
-
|
|
29
|
-
using namespace std;
|
|
30
|
-
|
|
31
|
-
constexpr auto APP_NAME = "MMKV";
|
|
32
|
-
|
|
33
|
-
static LogLevel MMKVLogLevelDesc(MMKVLogLevel level) {
|
|
34
|
-
switch (level) {
|
|
35
|
-
case MMKVLogDebug:
|
|
36
|
-
return LOG_DEBUG;
|
|
37
|
-
case MMKVLogInfo:
|
|
38
|
-
return LOG_INFO;
|
|
39
|
-
case MMKVLogWarning:
|
|
40
|
-
return LOG_WARN;
|
|
41
|
-
case MMKVLogError:
|
|
42
|
-
return LOG_ERROR;
|
|
43
|
-
default:
|
|
44
|
-
return LOG_INFO;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
void _MMKVLogWithLevel(MMKVLogLevel level, const char *filename, const char *func, int line, const char *format, ...) {
|
|
49
|
-
if (level >= g_currentLogLevel) {
|
|
50
|
-
string message;
|
|
51
|
-
char buffer[16];
|
|
52
|
-
|
|
53
|
-
va_list args;
|
|
54
|
-
va_start(args, format);
|
|
55
|
-
auto length = std::vsnprintf(buffer, sizeof(buffer), format, args);
|
|
56
|
-
va_end(args);
|
|
57
|
-
|
|
58
|
-
if (length < 0) { // something wrong
|
|
59
|
-
message = {};
|
|
60
|
-
} else if (length < sizeof(buffer)) {
|
|
61
|
-
message = string(buffer, static_cast<unsigned long>(length));
|
|
62
|
-
} else {
|
|
63
|
-
message.resize(static_cast<unsigned long>(length), '\0');
|
|
64
|
-
va_start(args, format);
|
|
65
|
-
std::vsnprintf(const_cast<char *>(message.data()), static_cast<size_t>(length) + 1, format, args);
|
|
66
|
-
va_end(args);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (g_logHandler) {
|
|
70
|
-
g_logHandler(level, filename, line, func, message);
|
|
71
|
-
} else {
|
|
72
|
-
auto desc = MMKVLogLevelDesc(level);
|
|
73
|
-
OH_LOG_Print(LOG_APP, desc, 0, APP_NAME, "<%{public}s:%{public}d::%{public}s> %{public}s",
|
|
74
|
-
filename, line, func, message.c_str());
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
# elif defined(MMKV_ANDROID)
|
|
80
|
-
# include <android/log.h>
|
|
81
|
-
# include <cstdarg>
|
|
82
|
-
# include <string>
|
|
83
|
-
|
|
84
|
-
using namespace std;
|
|
85
|
-
|
|
86
|
-
constexpr auto APP_NAME = "MMKV";
|
|
87
|
-
|
|
88
|
-
static android_LogPriority MMKVLogLevelDesc(MMKVLogLevel level) {
|
|
89
|
-
switch (level) {
|
|
90
|
-
case MMKVLogDebug:
|
|
91
|
-
return ANDROID_LOG_DEBUG;
|
|
92
|
-
case MMKVLogInfo:
|
|
93
|
-
return ANDROID_LOG_INFO;
|
|
94
|
-
case MMKVLogWarning:
|
|
95
|
-
return ANDROID_LOG_WARN;
|
|
96
|
-
case MMKVLogError:
|
|
97
|
-
return ANDROID_LOG_ERROR;
|
|
98
|
-
default:
|
|
99
|
-
return ANDROID_LOG_UNKNOWN;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
void _MMKVLogWithLevel(MMKVLogLevel level, const char *filename, const char *func, int line, const char *format, ...) {
|
|
104
|
-
if (level >= g_currentLogLevel) {
|
|
105
|
-
string message;
|
|
106
|
-
char buffer[16];
|
|
107
|
-
|
|
108
|
-
va_list args;
|
|
109
|
-
va_start(args, format);
|
|
110
|
-
auto length = std::vsnprintf(buffer, sizeof(buffer), format, args);
|
|
111
|
-
va_end(args);
|
|
112
|
-
|
|
113
|
-
if (length < 0) { // something wrong
|
|
114
|
-
message = {};
|
|
115
|
-
} else if (length < sizeof(buffer)) {
|
|
116
|
-
message = string(buffer, static_cast<unsigned long>(length));
|
|
117
|
-
} else {
|
|
118
|
-
message.resize(static_cast<unsigned long>(length), '\0');
|
|
119
|
-
va_start(args, format);
|
|
120
|
-
std::vsnprintf(const_cast<char *>(message.data()), static_cast<size_t>(length) + 1, format, args);
|
|
121
|
-
va_end(args);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (g_logHandler) {
|
|
125
|
-
g_logHandler(level, filename, line, func, message);
|
|
126
|
-
} else {
|
|
127
|
-
auto desc = MMKVLogLevelDesc(level);
|
|
128
|
-
__android_log_print(desc, APP_NAME, "<%s:%d::%s> %s", filename, line, func, message.c_str());
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
# endif // MMKV_ANDROID
|
|
133
|
-
|
|
134
|
-
#endif // ENABLE_MMKV_LOG
|
|
@@ -1,99 +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_MMKVMETAINFO_H
|
|
22
|
-
#define MMKV_MMKVMETAINFO_H
|
|
23
|
-
#ifdef __cplusplus
|
|
24
|
-
|
|
25
|
-
#include "aes/AESCrypt.h"
|
|
26
|
-
#include <cstdint>
|
|
27
|
-
#include <cstring>
|
|
28
|
-
|
|
29
|
-
namespace mmkv {
|
|
30
|
-
|
|
31
|
-
enum MMKVVersion : uint32_t {
|
|
32
|
-
MMKVVersionDefault = 0,
|
|
33
|
-
|
|
34
|
-
// record full write back count
|
|
35
|
-
MMKVVersionSequence = 1,
|
|
36
|
-
|
|
37
|
-
// store random iv for encryption
|
|
38
|
-
MMKVVersionRandomIV = 2,
|
|
39
|
-
|
|
40
|
-
// store actual size together with crc checksum, try to reduce file corruption
|
|
41
|
-
MMKVVersionActualSize = 3,
|
|
42
|
-
|
|
43
|
-
// store extra flags
|
|
44
|
-
MMKVVersionFlag = 4,
|
|
45
|
-
|
|
46
|
-
// preserved for next use
|
|
47
|
-
MMKVVersionNext = 5,
|
|
48
|
-
|
|
49
|
-
// always large than next, a placeholder for error check
|
|
50
|
-
MMKVVersionHolder = MMKVVersionNext + 1,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
struct MMKVMetaInfo {
|
|
54
|
-
uint32_t m_crcDigest = 0;
|
|
55
|
-
uint32_t m_version = MMKVVersionSequence;
|
|
56
|
-
uint32_t m_sequence = 0; // full write-back count
|
|
57
|
-
uint8_t m_vector[AES_KEY_LEN] = {};
|
|
58
|
-
uint32_t m_actualSize = 0;
|
|
59
|
-
|
|
60
|
-
// confirmed info: it's been synced to file
|
|
61
|
-
struct {
|
|
62
|
-
uint32_t lastActualSize = 0;
|
|
63
|
-
uint32_t lastCRCDigest = 0;
|
|
64
|
-
uint32_t _reserved[16] = {};
|
|
65
|
-
} m_lastConfirmedMetaInfo;
|
|
66
|
-
|
|
67
|
-
uint64_t m_flags = 0;
|
|
68
|
-
|
|
69
|
-
enum MMKVMetaInfoFlag : uint64_t {
|
|
70
|
-
EnableKeyExipre = 1 << 0,
|
|
71
|
-
};
|
|
72
|
-
bool hasFlag(MMKVMetaInfoFlag flag) { return (m_flags & flag) != 0; }
|
|
73
|
-
void setFlag(MMKVMetaInfoFlag flag) { m_flags |= flag; }
|
|
74
|
-
void unsetFlag(MMKVMetaInfoFlag flag) { m_flags &= ~flag; }
|
|
75
|
-
|
|
76
|
-
void write(void *ptr) const {
|
|
77
|
-
MMKV_ASSERT(ptr);
|
|
78
|
-
memcpy(ptr, this, sizeof(MMKVMetaInfo));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
void writeCRCAndActualSizeOnly(void *ptr) const {
|
|
82
|
-
MMKV_ASSERT(ptr);
|
|
83
|
-
auto other = (MMKVMetaInfo *) ptr;
|
|
84
|
-
other->m_crcDigest = m_crcDigest;
|
|
85
|
-
other->m_actualSize = m_actualSize;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
void read(const void *ptr) {
|
|
89
|
-
MMKV_ASSERT(ptr);
|
|
90
|
-
memcpy(this, ptr, sizeof(MMKVMetaInfo));
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
static_assert(sizeof(MMKVMetaInfo) <= (4 * 1024), "MMKVMetaInfo lager than one pagesize");
|
|
95
|
-
|
|
96
|
-
} // namespace mmkv
|
|
97
|
-
|
|
98
|
-
#endif
|
|
99
|
-
#endif //MMKV_MMKVMETAINFO_H
|