react-native-mmkv-dz 2.5.1
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/LICENSE +219 -0
- package/MMKV/CHANGELOG.md +553 -0
- package/MMKV/Core/CMakeLists.txt +153 -0
- package/MMKV/Core/CodedInputData.cpp +228 -0
- package/MMKV/Core/CodedInputData.h +83 -0
- package/MMKV/Core/CodedInputDataCrypt.cpp +280 -0
- package/MMKV/Core/CodedInputDataCrypt.h +87 -0
- package/MMKV/Core/CodedInputDataCrypt_OSX.cpp +62 -0
- package/MMKV/Core/CodedInputData_OSX.cpp +92 -0
- package/MMKV/Core/CodedOutputData.cpp +174 -0
- package/MMKV/Core/CodedOutputData.h +82 -0
- package/MMKV/Core/Core.xcodeproj/project.pbxproj +702 -0
- package/MMKV/Core/Core.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/MMKV/Core/Core.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme +67 -0
- package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/MMKVWatchCore.xcscheme +67 -0
- package/MMKV/Core/InterProcessLock.cpp +186 -0
- package/MMKV/Core/InterProcessLock.h +119 -0
- package/MMKV/Core/InterProcessLock_Android.cpp +103 -0
- package/MMKV/Core/InterProcessLock_Win32.cpp +108 -0
- package/MMKV/Core/KeyValueHolder.cpp +236 -0
- package/MMKV/Core/KeyValueHolder.h +118 -0
- package/MMKV/Core/MMBuffer.cpp +185 -0
- package/MMKV/Core/MMBuffer.h +107 -0
- package/MMKV/Core/MMKV.cpp +1418 -0
- package/MMKV/Core/MMKV.h +386 -0
- package/MMKV/Core/MMKVLog.cpp +127 -0
- package/MMKV/Core/MMKVLog.h +86 -0
- package/MMKV/Core/MMKVLog_Android.cpp +79 -0
- package/MMKV/Core/MMKVMetaInfo.hpp +81 -0
- package/MMKV/Core/MMKVPredef.h +245 -0
- package/MMKV/Core/MMKV_Android.cpp +259 -0
- package/MMKV/Core/MMKV_IO.cpp +1119 -0
- package/MMKV/Core/MMKV_IO.h +57 -0
- package/MMKV/Core/MMKV_OSX.cpp +347 -0
- package/MMKV/Core/MMKV_OSX.h +51 -0
- package/MMKV/Core/MemoryFile.cpp +537 -0
- package/MMKV/Core/MemoryFile.h +182 -0
- package/MMKV/Core/MemoryFile_Android.cpp +211 -0
- package/MMKV/Core/MemoryFile_Linux.cpp +120 -0
- package/MMKV/Core/MemoryFile_OSX.cpp +142 -0
- package/MMKV/Core/MemoryFile_Win32.cpp +536 -0
- package/MMKV/Core/MiniPBCoder.cpp +366 -0
- package/MMKV/Core/MiniPBCoder.h +129 -0
- package/MMKV/Core/MiniPBCoder_OSX.cpp +228 -0
- package/MMKV/Core/PBEncodeItem.hpp +86 -0
- package/MMKV/Core/PBUtility.cpp +61 -0
- package/MMKV/Core/PBUtility.h +153 -0
- package/MMKV/Core/ScopedLock.hpp +69 -0
- package/MMKV/Core/ThreadLock.cpp +68 -0
- package/MMKV/Core/ThreadLock.h +78 -0
- package/MMKV/Core/ThreadLock_Win32.cpp +89 -0
- package/MMKV/Core/aes/AESCrypt.cpp +256 -0
- package/MMKV/Core/aes/AESCrypt.h +107 -0
- package/MMKV/Core/aes/openssl/openssl_aes-armv4.S +1231 -0
- package/MMKV/Core/aes/openssl/openssl_aes.h +118 -0
- package/MMKV/Core/aes/openssl/openssl_aes_core.cpp +1044 -0
- package/MMKV/Core/aes/openssl/openssl_aes_locl.h +38 -0
- package/MMKV/Core/aes/openssl/openssl_aesv8-armx.S +308 -0
- package/MMKV/Core/aes/openssl/openssl_arm_arch.h +84 -0
- package/MMKV/Core/aes/openssl/openssl_cfb128.cpp +97 -0
- package/MMKV/Core/aes/openssl/openssl_md32_common.h +254 -0
- package/MMKV/Core/aes/openssl/openssl_md5.h +49 -0
- package/MMKV/Core/aes/openssl/openssl_md5_dgst.cpp +166 -0
- package/MMKV/Core/aes/openssl/openssl_md5_locl.h +75 -0
- package/MMKV/Core/aes/openssl/openssl_md5_one.cpp +30 -0
- package/MMKV/Core/aes/openssl/openssl_opensslconf.h +271 -0
- package/MMKV/Core/core.vcxproj +186 -0
- package/MMKV/Core/core.vcxproj.filters +150 -0
- package/MMKV/Core/crc32/Checksum.h +67 -0
- package/MMKV/Core/crc32/crc32_armv8.cpp +132 -0
- package/MMKV/Core/crc32/zlib/crc32.cpp +55 -0
- package/MMKV/Core/crc32/zlib/crc32.h +48 -0
- package/MMKV/Core/crc32/zlib/zconf.h +380 -0
- package/MMKV/Core/crc32/zlib/zutil.h +25 -0
- package/MMKV/LICENSE.TXT +193 -0
- package/MMKV/README.md +288 -0
- package/README.md +221 -0
- package/android/CMakeLists.txt +71 -0
- package/android/build.gradle +371 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/cpp/MmkvHostObject.cpp +302 -0
- package/android/src/main/cpp/MmkvHostObject.h +26 -0
- package/android/src/main/cpp/cpp-adapter.cpp +65 -0
- package/android/src/main/java/com/reactnativemmkv/MmkvModule.java +49 -0
- package/android/src/main/java/com/reactnativemmkv/MmkvPackage.java +26 -0
- package/cpp/TypedArray.cpp +341 -0
- package/cpp/TypedArray.h +175 -0
- package/ios/JSIUtils.h +50 -0
- package/ios/JSIUtils.mm +194 -0
- package/ios/Mmkv.xcodeproj/project.pbxproj +291 -0
- package/ios/MmkvHostObject.h +27 -0
- package/ios/MmkvHostObject.mm +299 -0
- package/ios/MmkvModule.h +5 -0
- package/ios/MmkvModule.mm +73 -0
- package/lib/commonjs/MMKV.js +146 -0
- package/lib/commonjs/MMKV.js.map +1 -0
- package/lib/commonjs/PlatformChecker.js +16 -0
- package/lib/commonjs/PlatformChecker.js.map +1 -0
- package/lib/commonjs/createMMKV.js +66 -0
- package/lib/commonjs/createMMKV.js.map +1 -0
- package/lib/commonjs/createMMKV.mock.js +40 -0
- package/lib/commonjs/createMMKV.mock.js.map +1 -0
- package/lib/commonjs/createMMKV.web.js +77 -0
- package/lib/commonjs/createMMKV.web.js.map +1 -0
- package/lib/commonjs/createTextEncoder.js +24 -0
- package/lib/commonjs/createTextEncoder.js.map +1 -0
- package/lib/commonjs/hooks.js +200 -0
- package/lib/commonjs/hooks.js.map +1 -0
- package/lib/commonjs/index.js +32 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/MMKV.js +134 -0
- package/lib/module/MMKV.js.map +1 -0
- package/lib/module/PlatformChecker.js +9 -0
- package/lib/module/PlatformChecker.js.map +1 -0
- package/lib/module/createMMKV.js +55 -0
- package/lib/module/createMMKV.js.map +1 -0
- package/lib/module/createMMKV.mock.js +31 -0
- package/lib/module/createMMKV.mock.js.map +1 -0
- package/lib/module/createMMKV.web.js +67 -0
- package/lib/module/createMMKV.web.js.map +1 -0
- package/lib/module/createTextEncoder.js +17 -0
- package/lib/module/createTextEncoder.js.map +1 -0
- package/lib/module/hooks.js +181 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/MMKV.d.ts +137 -0
- package/lib/typescript/PlatformChecker.d.ts +1 -0
- package/lib/typescript/createMMKV.d.ts +6 -0
- package/lib/typescript/createMMKV.mock.d.ts +2 -0
- package/lib/typescript/createMMKV.web.d.ts +2 -0
- package/lib/typescript/createTextEncoder.d.ts +1 -0
- package/lib/typescript/hooks.d.ts +81 -0
- package/lib/typescript/index.d.ts +2 -0
- package/package.json +168 -0
- package/react-native-mmkv.podspec +32 -0
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
# Sets the minimum version of CMake required to build the native library.
|
|
22
|
+
|
|
23
|
+
cmake_minimum_required(VERSION 3.10.0)
|
|
24
|
+
|
|
25
|
+
IF(APPLE)
|
|
26
|
+
# tell ranlib to ignore empty compilation units
|
|
27
|
+
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
|
28
|
+
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
|
29
|
+
# prevents ar from invoking ranlib, let CMake do it
|
|
30
|
+
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qc -S <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
31
|
+
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qc -S <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
32
|
+
|
|
33
|
+
add_compile_definitions(FORCE_POSIX)
|
|
34
|
+
ENDIF()
|
|
35
|
+
|
|
36
|
+
set(can_use_assembler TRUE)
|
|
37
|
+
enable_language(ASM)
|
|
38
|
+
IF("${ANDROID_ABI}" STREQUAL "arm64-v8a")
|
|
39
|
+
SET(ASM_OPTIONS "-x assembler-with-cpp")
|
|
40
|
+
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS} -march=armv8+crypto -D__ANDROID__")
|
|
41
|
+
ELSEIF("${ANDROID_ABI}" STREQUAL "armeabi-v7a")
|
|
42
|
+
SET(ASM_OPTIONS "-x assembler-with-cpp")
|
|
43
|
+
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS} -march=armv7a -D__ANDROID__")
|
|
44
|
+
ELSEIF("${ANDROID_ABI}" STREQUAL "armeabi")
|
|
45
|
+
SET(ASM_OPTIONS "-x assembler-with-cpp")
|
|
46
|
+
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS} -march=armv5 -D__ANDROID__")
|
|
47
|
+
ENDIF()
|
|
48
|
+
|
|
49
|
+
#include(CMakePrintHelpers)
|
|
50
|
+
#cmake_print_variables(CMAKE_SYSTEM_PROCESSOR)
|
|
51
|
+
IF(UNIX AND (NOT APPLE))
|
|
52
|
+
IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
|
|
53
|
+
SET(ASM_OPTIONS "-x assembler-with-cpp")
|
|
54
|
+
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS} -march=armv8-a+crypto")
|
|
55
|
+
ENDIF()
|
|
56
|
+
ENDIF()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
project(core)
|
|
60
|
+
|
|
61
|
+
# Creates and names a library, sets it as either STATIC
|
|
62
|
+
# or SHARED, and provides the relative paths to its source code.
|
|
63
|
+
# You can define multiple libraries, and CMake builds them for you.
|
|
64
|
+
# Gradle automatically packages shared libraries with your APK.
|
|
65
|
+
|
|
66
|
+
add_library(core
|
|
67
|
+
|
|
68
|
+
# Sets the library as a shared library.
|
|
69
|
+
STATIC
|
|
70
|
+
|
|
71
|
+
# Provides a relative path to your source file(s).
|
|
72
|
+
MMKV.h
|
|
73
|
+
MMKV.cpp
|
|
74
|
+
MMKV_Android.cpp
|
|
75
|
+
MMKV_IO.h
|
|
76
|
+
MMKV_IO.cpp
|
|
77
|
+
MMKV_OSX.cpp
|
|
78
|
+
MMKVLog.h
|
|
79
|
+
MMKVLog.cpp
|
|
80
|
+
MMKVLog_Android.cpp
|
|
81
|
+
CodedInputData.h
|
|
82
|
+
CodedInputData.cpp
|
|
83
|
+
CodedInputData_OSX.cpp
|
|
84
|
+
CodedInputDataCrypt.h
|
|
85
|
+
CodedInputDataCrypt.cpp
|
|
86
|
+
CodedInputDataCrypt_OSX.cpp
|
|
87
|
+
CodedOutputData.h
|
|
88
|
+
CodedOutputData.cpp
|
|
89
|
+
KeyValueHolder.h
|
|
90
|
+
KeyValueHolder.cpp
|
|
91
|
+
PBUtility.h
|
|
92
|
+
PBUtility.cpp
|
|
93
|
+
MiniPBCoder.h
|
|
94
|
+
MiniPBCoder.cpp
|
|
95
|
+
MiniPBCoder_OSX.cpp
|
|
96
|
+
MMBuffer.h
|
|
97
|
+
MMBuffer.cpp
|
|
98
|
+
InterProcessLock.h
|
|
99
|
+
InterProcessLock.cpp
|
|
100
|
+
InterProcessLock_Win32.cpp
|
|
101
|
+
InterProcessLock_Android.cpp
|
|
102
|
+
MemoryFile.h
|
|
103
|
+
MemoryFile.cpp
|
|
104
|
+
MemoryFile_Android.cpp
|
|
105
|
+
MemoryFile_Linux.cpp
|
|
106
|
+
MemoryFile_Win32.cpp
|
|
107
|
+
MemoryFile_OSX.cpp
|
|
108
|
+
ThreadLock.h
|
|
109
|
+
ThreadLock.cpp
|
|
110
|
+
ThreadLock_Win32.cpp
|
|
111
|
+
MMKVMetaInfo.hpp
|
|
112
|
+
aes/AESCrypt.h
|
|
113
|
+
aes/AESCrypt.cpp
|
|
114
|
+
aes/openssl/openssl_aes.h
|
|
115
|
+
aes/openssl/openssl_aes_core.cpp
|
|
116
|
+
aes/openssl/openssl_aes_locl.h
|
|
117
|
+
aes/openssl/openssl_cfb128.cpp
|
|
118
|
+
aes/openssl/openssl_opensslconf.h
|
|
119
|
+
aes/openssl/openssl_md5_dgst.cpp
|
|
120
|
+
aes/openssl/openssl_md5_locl.h
|
|
121
|
+
aes/openssl/openssl_md5_one.cpp
|
|
122
|
+
aes/openssl/openssl_md5.h
|
|
123
|
+
aes/openssl/openssl_md32_common.h
|
|
124
|
+
aes/openssl/openssl_aesv8-armx.S
|
|
125
|
+
aes/openssl/openssl_aes-armv4.S
|
|
126
|
+
aes/openssl/openssl_arm_arch.h
|
|
127
|
+
crc32/Checksum.h
|
|
128
|
+
crc32/crc32_armv8.cpp
|
|
129
|
+
crc32/zlib/zconf.h
|
|
130
|
+
crc32/zlib/zutil.h
|
|
131
|
+
crc32/zlib/crc32.h
|
|
132
|
+
crc32/zlib/crc32.cpp
|
|
133
|
+
MMKVPredef.h
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
137
|
+
|
|
138
|
+
set_target_properties(core PROPERTIES
|
|
139
|
+
CXX_STANDARD 17
|
|
140
|
+
CXX_EXTENSIONS OFF
|
|
141
|
+
POSITION_INDEPENDENT_CODE ON
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
find_library(zlib
|
|
145
|
+
z
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
IF (NOT zlib)
|
|
149
|
+
target_compile_definitions(core PUBLIC MMKV_EMBED_ZLIB=1)
|
|
150
|
+
ELSE()
|
|
151
|
+
target_link_libraries(core ${zlib})
|
|
152
|
+
ENDIF()
|
|
153
|
+
|
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
#include "CodedInputData.h"
|
|
22
|
+
#include "PBUtility.h"
|
|
23
|
+
#include <stdexcept>
|
|
24
|
+
|
|
25
|
+
#ifdef MMKV_APPLE
|
|
26
|
+
# if __has_feature(objc_arc)
|
|
27
|
+
# error This file must be compiled with MRC. Use -fno-objc-arc flag.
|
|
28
|
+
# endif
|
|
29
|
+
#endif // MMKV_APPLE
|
|
30
|
+
|
|
31
|
+
using namespace std;
|
|
32
|
+
|
|
33
|
+
namespace mmkv {
|
|
34
|
+
|
|
35
|
+
CodedInputData::CodedInputData(const void *oData, size_t length)
|
|
36
|
+
: m_ptr((uint8_t *) oData), m_size(length), m_position(0) {
|
|
37
|
+
MMKV_ASSERT(m_ptr);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void CodedInputData::seek(size_t addedSize) {
|
|
41
|
+
if (m_position + addedSize > m_size) {
|
|
42
|
+
throw out_of_range("OutOfSpace");
|
|
43
|
+
}
|
|
44
|
+
m_position += addedSize;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
double CodedInputData::readDouble() {
|
|
48
|
+
return Int64ToFloat64(this->readRawLittleEndian64());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
float CodedInputData::readFloat() {
|
|
52
|
+
return Int32ToFloat32(this->readRawLittleEndian32());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
int64_t CodedInputData::readInt64() {
|
|
56
|
+
int32_t shift = 0;
|
|
57
|
+
int64_t result = 0;
|
|
58
|
+
while (shift < 64) {
|
|
59
|
+
int8_t b = this->readRawByte();
|
|
60
|
+
result |= (int64_t)(b & 0x7f) << shift;
|
|
61
|
+
if ((b & 0x80) == 0) {
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
shift += 7;
|
|
65
|
+
}
|
|
66
|
+
throw invalid_argument("InvalidProtocolBuffer malformedInt64");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
uint64_t CodedInputData::readUInt64() {
|
|
70
|
+
return static_cast<uint64_t>(readInt64());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
int32_t CodedInputData::readInt32() {
|
|
74
|
+
return this->readRawVarint32();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
uint32_t CodedInputData::readUInt32() {
|
|
78
|
+
return static_cast<uint32_t>(readRawVarint32());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
bool CodedInputData::readBool() {
|
|
82
|
+
return this->readRawVarint32() != 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#ifndef MMKV_APPLE
|
|
86
|
+
|
|
87
|
+
string CodedInputData::readString() {
|
|
88
|
+
int32_t size = readRawVarint32();
|
|
89
|
+
if (size < 0) {
|
|
90
|
+
throw length_error("InvalidProtocolBuffer negativeSize");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
auto s_size = static_cast<size_t>(size);
|
|
94
|
+
if (s_size <= m_size - m_position) {
|
|
95
|
+
string result((char *) (m_ptr + m_position), s_size);
|
|
96
|
+
m_position += s_size;
|
|
97
|
+
return result;
|
|
98
|
+
} else {
|
|
99
|
+
throw out_of_range("InvalidProtocolBuffer truncatedMessage");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
string CodedInputData::readString(KeyValueHolder &kvHolder) {
|
|
104
|
+
kvHolder.offset = static_cast<uint32_t>(m_position);
|
|
105
|
+
|
|
106
|
+
int32_t size = this->readRawVarint32();
|
|
107
|
+
if (size < 0) {
|
|
108
|
+
throw length_error("InvalidProtocolBuffer negativeSize");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
auto s_size = static_cast<size_t>(size);
|
|
112
|
+
if (s_size <= m_size - m_position) {
|
|
113
|
+
kvHolder.keySize = static_cast<uint16_t>(s_size);
|
|
114
|
+
|
|
115
|
+
auto ptr = m_ptr + m_position;
|
|
116
|
+
string result((char *) (m_ptr + m_position), s_size);
|
|
117
|
+
m_position += s_size;
|
|
118
|
+
return result;
|
|
119
|
+
} else {
|
|
120
|
+
throw out_of_range("InvalidProtocolBuffer truncatedMessage");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#endif
|
|
125
|
+
|
|
126
|
+
MMBuffer CodedInputData::readData() {
|
|
127
|
+
int32_t size = this->readRawVarint32();
|
|
128
|
+
if (size < 0) {
|
|
129
|
+
throw length_error("InvalidProtocolBuffer negativeSize");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
auto s_size = static_cast<size_t>(size);
|
|
133
|
+
if (s_size <= m_size - m_position) {
|
|
134
|
+
MMBuffer data(((int8_t *) m_ptr) + m_position, s_size);
|
|
135
|
+
m_position += s_size;
|
|
136
|
+
return data;
|
|
137
|
+
} else {
|
|
138
|
+
throw out_of_range("InvalidProtocolBuffer truncatedMessage");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
void CodedInputData::readData(KeyValueHolder &kvHolder) {
|
|
143
|
+
int32_t size = this->readRawVarint32();
|
|
144
|
+
if (size < 0) {
|
|
145
|
+
throw length_error("InvalidProtocolBuffer negativeSize");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
auto s_size = static_cast<size_t>(size);
|
|
149
|
+
if (s_size <= m_size - m_position) {
|
|
150
|
+
kvHolder.computedKVSize = static_cast<uint16_t>(m_position - kvHolder.offset);
|
|
151
|
+
kvHolder.valueSize = static_cast<uint32_t>(s_size);
|
|
152
|
+
|
|
153
|
+
m_position += s_size;
|
|
154
|
+
} else {
|
|
155
|
+
throw out_of_range("InvalidProtocolBuffer truncatedMessage");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
int32_t CodedInputData::readRawVarint32() {
|
|
160
|
+
int8_t tmp = this->readRawByte();
|
|
161
|
+
if (tmp >= 0) {
|
|
162
|
+
return tmp;
|
|
163
|
+
}
|
|
164
|
+
int32_t result = tmp & 0x7f;
|
|
165
|
+
if ((tmp = this->readRawByte()) >= 0) {
|
|
166
|
+
result |= tmp << 7;
|
|
167
|
+
} else {
|
|
168
|
+
result |= (tmp & 0x7f) << 7;
|
|
169
|
+
if ((tmp = this->readRawByte()) >= 0) {
|
|
170
|
+
result |= tmp << 14;
|
|
171
|
+
} else {
|
|
172
|
+
result |= (tmp & 0x7f) << 14;
|
|
173
|
+
if ((tmp = this->readRawByte()) >= 0) {
|
|
174
|
+
result |= tmp << 21;
|
|
175
|
+
} else {
|
|
176
|
+
result |= (tmp & 0x7f) << 21;
|
|
177
|
+
result |= (tmp = this->readRawByte()) << 28;
|
|
178
|
+
if (tmp < 0) {
|
|
179
|
+
// discard upper 32 bits
|
|
180
|
+
for (int i = 0; i < 5; i++) {
|
|
181
|
+
if (this->readRawByte() >= 0) {
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
throw invalid_argument("InvalidProtocolBuffer malformed varint32");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
int32_t CodedInputData::readRawLittleEndian32() {
|
|
194
|
+
int8_t b1 = this->readRawByte();
|
|
195
|
+
int8_t b2 = this->readRawByte();
|
|
196
|
+
int8_t b3 = this->readRawByte();
|
|
197
|
+
int8_t b4 = this->readRawByte();
|
|
198
|
+
return (((int32_t) b1 & 0xff)) | (((int32_t) b2 & 0xff) << 8) | (((int32_t) b3 & 0xff) << 16) |
|
|
199
|
+
(((int32_t) b4 & 0xff) << 24);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
int64_t CodedInputData::readRawLittleEndian64() {
|
|
203
|
+
int8_t b1 = this->readRawByte();
|
|
204
|
+
int8_t b2 = this->readRawByte();
|
|
205
|
+
int8_t b3 = this->readRawByte();
|
|
206
|
+
int8_t b4 = this->readRawByte();
|
|
207
|
+
int8_t b5 = this->readRawByte();
|
|
208
|
+
int8_t b6 = this->readRawByte();
|
|
209
|
+
int8_t b7 = this->readRawByte();
|
|
210
|
+
int8_t b8 = this->readRawByte();
|
|
211
|
+
return (((int64_t) b1 & 0xff)) | (((int64_t) b2 & 0xff) << 8) | (((int64_t) b3 & 0xff) << 16) |
|
|
212
|
+
(((int64_t) b4 & 0xff) << 24) | (((int64_t) b5 & 0xff) << 32) | (((int64_t) b6 & 0xff) << 40) |
|
|
213
|
+
(((int64_t) b7 & 0xff) << 48) | (((int64_t) b8 & 0xff) << 56);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
int8_t CodedInputData::readRawByte() {
|
|
217
|
+
if (m_position == m_size) {
|
|
218
|
+
auto msg = "reach end, m_position: " + to_string(m_position) + ", m_size: " + to_string(m_size);
|
|
219
|
+
throw out_of_range(msg);
|
|
220
|
+
}
|
|
221
|
+
auto *bytes = (int8_t *) m_ptr;
|
|
222
|
+
return bytes[m_position++];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#ifdef MMKV_APPLE
|
|
226
|
+
#endif // MMKV_APPLE
|
|
227
|
+
|
|
228
|
+
} // namespace mmkv
|
|
@@ -0,0 +1,83 @@
|
|
|
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_CODEDINPUTDATA_H
|
|
22
|
+
#define MMKV_CODEDINPUTDATA_H
|
|
23
|
+
#ifdef __cplusplus
|
|
24
|
+
|
|
25
|
+
#include "MMKVPredef.h"
|
|
26
|
+
|
|
27
|
+
#include "KeyValueHolder.h"
|
|
28
|
+
#include "MMBuffer.h"
|
|
29
|
+
#include <cstdint>
|
|
30
|
+
|
|
31
|
+
namespace mmkv {
|
|
32
|
+
|
|
33
|
+
class CodedInputData {
|
|
34
|
+
uint8_t *const m_ptr;
|
|
35
|
+
size_t m_size;
|
|
36
|
+
size_t m_position;
|
|
37
|
+
|
|
38
|
+
int8_t readRawByte();
|
|
39
|
+
|
|
40
|
+
int32_t readRawVarint32();
|
|
41
|
+
|
|
42
|
+
int32_t readRawLittleEndian32();
|
|
43
|
+
|
|
44
|
+
int64_t readRawLittleEndian64();
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
CodedInputData(const void *oData, size_t length);
|
|
48
|
+
|
|
49
|
+
bool isAtEnd() const { return m_position == m_size; };
|
|
50
|
+
|
|
51
|
+
void seek(size_t addedSize);
|
|
52
|
+
|
|
53
|
+
bool readBool();
|
|
54
|
+
|
|
55
|
+
double readDouble();
|
|
56
|
+
|
|
57
|
+
float readFloat();
|
|
58
|
+
|
|
59
|
+
int64_t readInt64();
|
|
60
|
+
|
|
61
|
+
uint64_t readUInt64();
|
|
62
|
+
|
|
63
|
+
int32_t readInt32();
|
|
64
|
+
|
|
65
|
+
uint32_t readUInt32();
|
|
66
|
+
|
|
67
|
+
MMBuffer readData();
|
|
68
|
+
void readData(KeyValueHolder &kvHolder);
|
|
69
|
+
|
|
70
|
+
#ifndef MMKV_APPLE
|
|
71
|
+
std::string readString();
|
|
72
|
+
std::string readString(KeyValueHolder &kvHolder);
|
|
73
|
+
#else
|
|
74
|
+
NSString *readString();
|
|
75
|
+
NSString *readString(KeyValueHolder &kvHolder);
|
|
76
|
+
NSData *readNSData();
|
|
77
|
+
#endif
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace mmkv
|
|
81
|
+
|
|
82
|
+
#endif
|
|
83
|
+
#endif //MMKV_CODEDINPUTDATA_H
|