react-native-quick-crypto 0.7.3 → 1.0.0-beta.2
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/QuickCrypto.podspec +34 -0
- package/README.md +13 -46
- package/android/CMakeLists.txt +32 -64
- package/android/build.gradle +52 -125
- package/android/gradle.properties +4 -4
- package/android/src/main/cpp/cpp-adapter.cpp +9 -54
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
- package/cpp/random/HybridRandom.cpp +34 -0
- package/cpp/random/HybridRandom.hpp +44 -0
- package/cpp/utils/Utils.hpp +9 -0
- package/ios/QuickCryptoOnLoad.mm +19 -0
- package/lib/commonjs/index.js +39 -39
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/random.js +26 -12
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/commonjs/utils/conversion.js +22 -0
- package/lib/commonjs/utils/conversion.js.map +1 -0
- package/lib/commonjs/utils/index.js +12 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/types.js +2 -0
- package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
- package/lib/module/index.js +38 -38
- package/lib/module/index.js.map +1 -1
- package/lib/module/random.js +26 -12
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/random.nitro.js +4 -0
- package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/module/utils/conversion.js +16 -0
- package/lib/module/utils/conversion.js.map +1 -0
- package/lib/module/utils/index.js +8 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/types.js +2 -0
- package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/typescript/index.d.ts +10 -141
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/random.d.ts +4 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/random.nitro.d.ts +9 -0
- package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +4 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +5 -0
- package/lib/typescript/utils/types.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +45 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +26 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +57 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +9 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +62 -0
- package/package.json +50 -106
- package/src/index.ts +38 -48
- package/src/random.ts +51 -48
- package/src/specs/random.nitro.ts +14 -0
- package/src/utils/conversion.ts +16 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/types.ts +15 -0
- package/LICENSE +0 -27
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
- package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
- package/cpp/Cipher/MGLCipherHostObject.h +0 -90
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
- package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
- package/cpp/Cipher/MGLPublicCipher.h +0 -124
- package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
- package/cpp/Cipher/MGLRsa.cpp +0 -573
- package/cpp/Cipher/MGLRsa.h +0 -109
- package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
- package/cpp/HMAC/MGLHmacHostObject.h +0 -39
- package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
- package/cpp/HMAC/MGLHmacInstaller.h +0 -20
- package/cpp/Hash/MGLHashHostObject.cpp +0 -147
- package/cpp/Hash/MGLHashHostObject.h +0 -53
- package/cpp/Hash/MGLHashInstaller.cpp +0 -44
- package/cpp/Hash/MGLHashInstaller.h +0 -20
- package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
- package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
- package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
- package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
- package/cpp/JSIUtils/MGLTypedArray.h +0 -160
- package/cpp/MGLKeys.cpp +0 -1426
- package/cpp/MGLKeys.h +0 -203
- package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
- package/cpp/MGLQuickCryptoHostObject.h +0 -30
- package/cpp/Random/MGLRandomHostObject.cpp +0 -96
- package/cpp/Random/MGLRandomHostObject.h +0 -27
- package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
- package/cpp/Sig/MGLSignHostObjects.h +0 -128
- package/cpp/Sig/MGLSignInstaller.cpp +0 -24
- package/cpp/Sig/MGLSignInstaller.h +0 -29
- package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
- package/cpp/Sig/MGLVerifyInstaller.h +0 -22
- package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
- package/cpp/Utils/MGLDispatchQueue.h +0 -55
- package/cpp/Utils/MGLUtils.cpp +0 -295
- package/cpp/Utils/MGLUtils.h +0 -358
- package/cpp/Utils/base64.h +0 -320
- package/cpp/Utils/logs.h +0 -38
- package/cpp/Utils/node.h +0 -13
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
- package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
- package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
- package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
- package/cpp/webcrypto/MGLWebCrypto.h +0 -32
- package/cpp/webcrypto/crypto_aes.cpp +0 -516
- package/cpp/webcrypto/crypto_aes.h +0 -79
- package/cpp/webcrypto/crypto_ec.cpp +0 -424
- package/cpp/webcrypto/crypto_ec.h +0 -78
- package/cpp/webcrypto/crypto_keygen.cpp +0 -86
- package/cpp/webcrypto/crypto_keygen.h +0 -38
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
- package/ios/QuickCryptoModule.h +0 -5
- package/ios/QuickCryptoModule.mm +0 -42
- package/lib/commonjs/Cipher.js +0 -502
- package/lib/commonjs/Cipher.js.map +0 -1
- package/lib/commonjs/Hash.js +0 -99
- package/lib/commonjs/Hash.js.map +0 -1
- package/lib/commonjs/Hashnames.js +0 -87
- package/lib/commonjs/Hashnames.js.map +0 -1
- package/lib/commonjs/Hmac.js +0 -79
- package/lib/commonjs/Hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/commonjs/Utils.js +0 -608
- package/lib/commonjs/Utils.js.map +0 -1
- package/lib/commonjs/aes.js +0 -281
- package/lib/commonjs/aes.js.map +0 -1
- package/lib/commonjs/constants.js +0 -85
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/ec.js +0 -276
- package/lib/commonjs/ec.js.map +0 -1
- package/lib/commonjs/keygen.js +0 -56
- package/lib/commonjs/keygen.js.map +0 -1
- package/lib/commonjs/keys.js +0 -492
- package/lib/commonjs/keys.js.map +0 -1
- package/lib/commonjs/pbkdf2.js +0 -90
- package/lib/commonjs/pbkdf2.js.map +0 -1
- package/lib/commonjs/rsa.js +0 -248
- package/lib/commonjs/rsa.js.map +0 -1
- package/lib/commonjs/sig.js +0 -129
- package/lib/commonjs/sig.js.map +0 -1
- package/lib/commonjs/subtle.js +0 -448
- package/lib/commonjs/subtle.js.map +0 -1
- package/lib/commonjs/webcrypto.js +0 -14
- package/lib/commonjs/webcrypto.js.map +0 -1
- package/lib/module/Cipher.js +0 -491
- package/lib/module/Cipher.js.map +0 -1
- package/lib/module/Hash.js +0 -93
- package/lib/module/Hash.js.map +0 -1
- package/lib/module/Hashnames.js +0 -85
- package/lib/module/Hashnames.js.map +0 -1
- package/lib/module/Hmac.js +0 -74
- package/lib/module/Hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
- package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/module/NativeQuickCrypto/aes.js +0 -4
- package/lib/module/NativeQuickCrypto/hash.js +0 -2
- package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/module/NativeQuickCrypto/hmac.js +0 -2
- package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/keygen.js +0 -4
- package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/module/NativeQuickCrypto/random.js +0 -2
- package/lib/module/NativeQuickCrypto/random.js.map +0 -1
- package/lib/module/NativeQuickCrypto/rsa.js +0 -4
- package/lib/module/NativeQuickCrypto/sig.js +0 -17
- package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
- package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/module/Utils.js +0 -539
- package/lib/module/Utils.js.map +0 -1
- package/lib/module/aes.js +0 -274
- package/lib/module/aes.js.map +0 -1
- package/lib/module/constants.js +0 -81
- package/lib/module/constants.js.map +0 -1
- package/lib/module/ec.js +0 -267
- package/lib/module/ec.js.map +0 -1
- package/lib/module/keygen.js +0 -49
- package/lib/module/keygen.js.map +0 -1
- package/lib/module/keys.js +0 -477
- package/lib/module/keys.js.map +0 -1
- package/lib/module/pbkdf2.js +0 -84
- package/lib/module/pbkdf2.js.map +0 -1
- package/lib/module/rsa.js +0 -242
- package/lib/module/rsa.js.map +0 -1
- package/lib/module/sig.js +0 -124
- package/lib/module/sig.js.map +0 -1
- package/lib/module/subtle.js +0 -443
- package/lib/module/subtle.js.map +0 -1
- package/lib/module/webcrypto.js +0 -10
- package/lib/module/webcrypto.js.map +0 -1
- package/lib/typescript/Cipher.d.ts +0 -81
- package/lib/typescript/Cipher.d.ts.map +0 -1
- package/lib/typescript/Hash.d.ts +0 -44
- package/lib/typescript/Hash.d.ts.map +0 -1
- package/lib/typescript/Hashnames.d.ts +0 -11
- package/lib/typescript/Hashnames.d.ts.map +0 -1
- package/lib/typescript/Hmac.d.ts +0 -37
- package/lib/typescript/Hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
- package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
- package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
- package/lib/typescript/Utils.d.ts +0 -48
- package/lib/typescript/Utils.d.ts.map +0 -1
- package/lib/typescript/aes.d.ts +0 -22
- package/lib/typescript/aes.d.ts.map +0 -1
- package/lib/typescript/constants.d.ts +0 -76
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/ec.d.ts +0 -7
- package/lib/typescript/ec.d.ts.map +0 -1
- package/lib/typescript/keygen.d.ts +0 -6
- package/lib/typescript/keygen.d.ts.map +0 -1
- package/lib/typescript/keys.d.ts +0 -206
- package/lib/typescript/keys.d.ts.map +0 -1
- package/lib/typescript/pbkdf2.d.ts +0 -12
- package/lib/typescript/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/rsa.d.ts +0 -12
- package/lib/typescript/rsa.d.ts.map +0 -1
- package/lib/typescript/sig.d.ts +0 -21
- package/lib/typescript/sig.d.ts.map +0 -1
- package/lib/typescript/subtle.d.ts +0 -15
- package/lib/typescript/subtle.d.ts.map +0 -1
- package/lib/typescript/webcrypto.d.ts +0 -9
- package/lib/typescript/webcrypto.d.ts.map +0 -1
- package/react-native-quick-crypto.podspec +0 -40
- package/src/Cipher.ts +0 -832
- package/src/Hash.ts +0 -132
- package/src/Hashnames.ts +0 -93
- package/src/Hmac.ts +0 -106
- package/src/NativeQuickCrypto/Cipher.ts +0 -102
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
- package/src/NativeQuickCrypto/aes.ts +0 -14
- package/src/NativeQuickCrypto/hash.ts +0 -10
- package/src/NativeQuickCrypto/hmac.ts +0 -9
- package/src/NativeQuickCrypto/keygen.ts +0 -7
- package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
- package/src/NativeQuickCrypto/random.ts +0 -12
- package/src/NativeQuickCrypto/rsa.ts +0 -12
- package/src/NativeQuickCrypto/sig.ts +0 -44
- package/src/NativeQuickCrypto/webcrypto.ts +0 -72
- package/src/Utils.ts +0 -777
- package/src/aes.ts +0 -402
- package/src/constants.ts +0 -79
- package/src/ec.ts +0 -375
- package/src/keygen.ts +0 -80
- package/src/keys.ts +0 -787
- package/src/pbkdf2.ts +0 -169
- package/src/rsa.ts +0 -370
- package/src/sig.ts +0 -164
- package/src/subtle.ts +0 -639
- package/src/webcrypto.ts +0 -8
- /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// MGLJSIUtils.h
|
|
3
|
-
// Pods
|
|
4
|
-
//
|
|
5
|
-
// Created by Oscar on 20.06.22.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#ifndef MGLJSIUtils_h
|
|
9
|
-
#define MGLJSIUtils_h
|
|
10
|
-
|
|
11
|
-
#include <jsi/jsi.h>
|
|
12
|
-
#include <limits>
|
|
13
|
-
|
|
14
|
-
namespace jsi = facebook::jsi;
|
|
15
|
-
|
|
16
|
-
inline bool CheckIsArrayBuffer(jsi::Runtime &runtime, const jsi::Value &value) {
|
|
17
|
-
return !value.isNull() && !value.isUndefined() && value.isObject() &&
|
|
18
|
-
value.asObject(runtime).isArrayBuffer(runtime);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
inline bool CheckSizeInt32(jsi::Runtime &runtime, jsi::ArrayBuffer &buffer) {
|
|
22
|
-
return buffer.size(runtime) <= INT_MAX;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
inline bool CheckIsInt32(const jsi::Value &value) {
|
|
26
|
-
if (!value.isNumber()) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
double d = value.asNumber();
|
|
30
|
-
return (d >= std::numeric_limits<int32_t>::lowest() && d <= std::numeric_limits<int32_t>::max());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
inline bool CheckIsUint32(const jsi::Value &value) {
|
|
34
|
-
if (!value.isNumber()) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
double d = value.asNumber();
|
|
38
|
-
return (d >= std::numeric_limits<uint32_t>::lowest() && d <= std::numeric_limits<uint32_t>::max());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
#endif /* MGLJSIUtils_h */
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 24/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#include "MGLSmartHostObject.h"
|
|
6
|
-
|
|
7
|
-
namespace margelo {
|
|
8
|
-
|
|
9
|
-
namespace jsi = facebook::jsi;
|
|
10
|
-
namespace react = facebook::react;
|
|
11
|
-
|
|
12
|
-
FieldDefinition buildPair(std::string name, jsi::HostFunctionType &&f) {
|
|
13
|
-
auto valueBuilder = [f, name](jsi::Runtime &runtime) {
|
|
14
|
-
const auto func = f;
|
|
15
|
-
auto propNameID = jsi::PropNameID::forAscii(runtime, name);
|
|
16
|
-
return jsi::Function::createFromHostFunction(runtime, propNameID, 0, func);
|
|
17
|
-
};
|
|
18
|
-
return std::make_pair(name, valueBuilder);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
std::vector<jsi::PropNameID> MGLSmartHostObject::getPropertyNames(
|
|
22
|
-
jsi::Runtime &runtime) {
|
|
23
|
-
std::vector<jsi::PropNameID> propertyNames;
|
|
24
|
-
for (auto field : fields) {
|
|
25
|
-
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, field.first));
|
|
26
|
-
}
|
|
27
|
-
return propertyNames;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// TODO(Szymon) maybe add memoization here
|
|
31
|
-
jsi::Value MGLSmartHostObject::get(jsi::Runtime &runtime,
|
|
32
|
-
const jsi::PropNameID &propNameId) {
|
|
33
|
-
auto name = propNameId.utf8(runtime);
|
|
34
|
-
for (auto field : fields) {
|
|
35
|
-
auto fieldName = field.first;
|
|
36
|
-
if (fieldName == name) {
|
|
37
|
-
return (field.second)(runtime);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return jsi::Value::undefined();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
} // namespace margelo
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 24/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#ifndef MGL_SMARTHOSTOBJECT_H
|
|
6
|
-
#define MGL_SMARTHOSTOBJECT_H
|
|
7
|
-
|
|
8
|
-
#include <ReactCommon/TurboModuleUtils.h>
|
|
9
|
-
|
|
10
|
-
#include <memory>
|
|
11
|
-
#include <string>
|
|
12
|
-
#include <utility>
|
|
13
|
-
#include <vector>
|
|
14
|
-
|
|
15
|
-
#include "MGLJSIMacros.h"
|
|
16
|
-
#include "MGLThreadAwareHostObject.h"
|
|
17
|
-
|
|
18
|
-
namespace margelo {
|
|
19
|
-
|
|
20
|
-
namespace jsi = facebook::jsi;
|
|
21
|
-
namespace react = facebook::react;
|
|
22
|
-
|
|
23
|
-
typedef std::function<jsi::Value(jsi::Runtime &runtime)> JSIValueBuilder;
|
|
24
|
-
|
|
25
|
-
typedef std::pair<std::string, JSIValueBuilder> FieldDefinition;
|
|
26
|
-
|
|
27
|
-
FieldDefinition buildPair(std::string name, jsi::HostFunctionType &&f);
|
|
28
|
-
|
|
29
|
-
class JSI_EXPORT MGLSmartHostObject : public MGLThreadAwareHostObject {
|
|
30
|
-
public:
|
|
31
|
-
MGLSmartHostObject(std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
32
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
|
|
33
|
-
: MGLThreadAwareHostObject(jsCallInvoker, workerQueue) {}
|
|
34
|
-
|
|
35
|
-
virtual ~MGLSmartHostObject() {}
|
|
36
|
-
|
|
37
|
-
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &runtime);
|
|
38
|
-
|
|
39
|
-
jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &propNameId);
|
|
40
|
-
|
|
41
|
-
std::vector<std::pair<std::string, JSIValueBuilder>> fields;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
} // namespace margelo
|
|
45
|
-
|
|
46
|
-
#endif // MGL_SMARTHOSTOBJECT_H
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 24/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#include "MGLThreadAwareHostObject.h"
|
|
6
|
-
|
|
7
|
-
#include <utility>
|
|
8
|
-
|
|
9
|
-
namespace margelo {
|
|
10
|
-
|
|
11
|
-
namespace jsi = facebook::jsi;
|
|
12
|
-
|
|
13
|
-
void MGLThreadAwareHostObject::runOnWorkerThread(std::function<void()> &&job) {
|
|
14
|
-
this->dispatchQueue->dispatch(job);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
void MGLThreadAwareHostObject::runOnJSThread(std::function<void()> &&job) {
|
|
18
|
-
auto callInvoker = this->weakJsCallInvoker.lock();
|
|
19
|
-
if (callInvoker != nullptr) {
|
|
20
|
-
callInvoker->invokeAsync(std::move(job));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
} // namespace margelo
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Szymon on 24/02/2022.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#ifndef MGL_THREADAWAREHOSTOBJECT_H
|
|
6
|
-
#define MGL_THREADAWAREHOSTOBJECT_H
|
|
7
|
-
|
|
8
|
-
#include <ReactCommon/CallInvoker.h>
|
|
9
|
-
#include <jsi/jsi.h>
|
|
10
|
-
|
|
11
|
-
#include <memory>
|
|
12
|
-
|
|
13
|
-
#ifdef ANDROID
|
|
14
|
-
#include "Utils/MGLDispatchQueue.h"
|
|
15
|
-
#else
|
|
16
|
-
#include "MGLDispatchQueue.h"
|
|
17
|
-
#endif
|
|
18
|
-
|
|
19
|
-
namespace margelo {
|
|
20
|
-
|
|
21
|
-
namespace jsi = facebook::jsi;
|
|
22
|
-
namespace react = facebook::react;
|
|
23
|
-
|
|
24
|
-
class JSI_EXPORT MGLThreadAwareHostObject : public jsi::HostObject {
|
|
25
|
-
public:
|
|
26
|
-
explicit MGLThreadAwareHostObject(
|
|
27
|
-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
|
|
28
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
|
|
29
|
-
: weakJsCallInvoker(jsCallInvoker), dispatchQueue(workerQueue) {}
|
|
30
|
-
|
|
31
|
-
virtual ~MGLThreadAwareHostObject() {}
|
|
32
|
-
|
|
33
|
-
void runOnWorkerThread(std::function<void(void)> &&job);
|
|
34
|
-
void runOnJSThread(std::function<void(void)> &&job);
|
|
35
|
-
|
|
36
|
-
protected:
|
|
37
|
-
std::weak_ptr<react::CallInvoker> weakJsCallInvoker;
|
|
38
|
-
std::shared_ptr<DispatchQueue::dispatch_queue> dispatchQueue;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
} // namespace margelo
|
|
42
|
-
|
|
43
|
-
#endif // MGL_THREADAWAREHOSTOBJECT_H
|
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// TypedArray.cpp
|
|
3
|
-
// react-native-quick-crypto
|
|
4
|
-
//
|
|
5
|
-
// Created by Marc Rousavy on 31.10.21.
|
|
6
|
-
// Originally created by Expo (expo-gl)
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#include "MGLTypedArray.h"
|
|
10
|
-
|
|
11
|
-
#include <algorithm>
|
|
12
|
-
#include <memory>
|
|
13
|
-
#include <string>
|
|
14
|
-
#include <unordered_map>
|
|
15
|
-
|
|
16
|
-
template <MGLTypedArrayKind T>
|
|
17
|
-
using ContentType = typename typedArrayTypeMap<T>::type;
|
|
18
|
-
|
|
19
|
-
enum class Prop {
|
|
20
|
-
Buffer, // "buffer"
|
|
21
|
-
Constructor, // "constructor"
|
|
22
|
-
Name, // "name"
|
|
23
|
-
Proto, // "__proto__"
|
|
24
|
-
Length, // "length"
|
|
25
|
-
ByteLength, // "byteLength"
|
|
26
|
-
ByteOffset, // "offset"
|
|
27
|
-
IsView, // "isView"
|
|
28
|
-
ArrayBuffer, // "ArrayBuffer"
|
|
29
|
-
Int8Array, // "Int8Array"
|
|
30
|
-
Int16Array, // "Int16Array"
|
|
31
|
-
Int32Array, // "Int32Array"
|
|
32
|
-
Uint8Array, // "Uint8Array"
|
|
33
|
-
Uint8ClampedArray, // "Uint8ClampedArray"
|
|
34
|
-
Uint16Array, // "Uint16Array"
|
|
35
|
-
Uint32Array, // "Uint32Array"
|
|
36
|
-
Float32Array, // "Float32Array"
|
|
37
|
-
Float64Array, // "Float64Array"
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
class PropNameIDCache {
|
|
41
|
-
public:
|
|
42
|
-
const jsi::PropNameID &get(jsi::Runtime &runtime, Prop prop) {
|
|
43
|
-
if (!this->props[prop]) {
|
|
44
|
-
this->props[prop] =
|
|
45
|
-
std::make_unique<jsi::PropNameID>(createProp(runtime, prop));
|
|
46
|
-
}
|
|
47
|
-
return *(this->props[prop]);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const jsi::PropNameID &getConstructorNameProp(jsi::Runtime &runtime,
|
|
51
|
-
MGLTypedArrayKind kind);
|
|
52
|
-
|
|
53
|
-
void invalidate() { props.erase(props.begin(), props.end()); }
|
|
54
|
-
|
|
55
|
-
private:
|
|
56
|
-
std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>> props;
|
|
57
|
-
|
|
58
|
-
jsi::PropNameID createProp(jsi::Runtime &runtime, Prop prop);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
PropNameIDCache propNameIDCache;
|
|
62
|
-
|
|
63
|
-
void invalidateJsiPropNameIDCache() { propNameIDCache.invalidate(); }
|
|
64
|
-
|
|
65
|
-
MGLTypedArrayKind getTypedArrayKindForName(const std::string &name);
|
|
66
|
-
|
|
67
|
-
MGLTypedArrayBase::MGLTypedArrayBase(jsi::Runtime &runtime, size_t size,
|
|
68
|
-
MGLTypedArrayKind kind)
|
|
69
|
-
: MGLTypedArrayBase(
|
|
70
|
-
runtime,
|
|
71
|
-
runtime.global()
|
|
72
|
-
.getProperty(runtime, propNameIDCache.getConstructorNameProp(
|
|
73
|
-
runtime, kind))
|
|
74
|
-
.asObject(runtime)
|
|
75
|
-
.asFunction(runtime)
|
|
76
|
-
.callAsConstructor(runtime, {static_cast<double>(size)})
|
|
77
|
-
.asObject(runtime)) {}
|
|
78
|
-
|
|
79
|
-
MGLTypedArrayBase::MGLTypedArrayBase(jsi::Runtime &runtime,
|
|
80
|
-
const jsi::Object &obj)
|
|
81
|
-
: jsi::Object(jsi::Value(runtime, obj).asObject(runtime)) {}
|
|
82
|
-
|
|
83
|
-
MGLTypedArrayKind MGLTypedArrayBase::getKind(jsi::Runtime &runtime) const {
|
|
84
|
-
auto constructorName =
|
|
85
|
-
this->getProperty(runtime,
|
|
86
|
-
propNameIDCache.get(runtime, Prop::Constructor))
|
|
87
|
-
.asObject(runtime)
|
|
88
|
-
.getProperty(runtime, propNameIDCache.get(runtime, Prop::Name))
|
|
89
|
-
.asString(runtime)
|
|
90
|
-
.utf8(runtime);
|
|
91
|
-
return getTypedArrayKindForName(constructorName);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
size_t MGLTypedArrayBase::size(jsi::Runtime &runtime) const {
|
|
95
|
-
return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length))
|
|
96
|
-
.asNumber();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
size_t MGLTypedArrayBase::length(jsi::Runtime &runtime) const {
|
|
100
|
-
return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length))
|
|
101
|
-
.asNumber();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
size_t MGLTypedArrayBase::byteLength(jsi::Runtime &runtime) const {
|
|
105
|
-
return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength))
|
|
106
|
-
.asNumber();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
size_t MGLTypedArrayBase::byteOffset(jsi::Runtime &runtime) const {
|
|
110
|
-
return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteOffset))
|
|
111
|
-
.asNumber();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
bool MGLTypedArrayBase::hasBuffer(jsi::Runtime &runtime) const {
|
|
115
|
-
auto buffer =
|
|
116
|
-
getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
|
|
117
|
-
return buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
std::vector<uint8_t> MGLTypedArrayBase::toVector(jsi::Runtime &runtime) {
|
|
121
|
-
auto start = reinterpret_cast<uint8_t *>(getBuffer(runtime).data(runtime) +
|
|
122
|
-
byteOffset(runtime));
|
|
123
|
-
auto end = start + byteLength(runtime);
|
|
124
|
-
return std::vector<uint8_t>(start, end);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
jsi::ArrayBuffer MGLTypedArrayBase::getBuffer(jsi::Runtime &runtime) const {
|
|
128
|
-
auto buffer =
|
|
129
|
-
getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
|
|
130
|
-
if (buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime)) {
|
|
131
|
-
return buffer.asObject(runtime).getArrayBuffer(runtime);
|
|
132
|
-
} else {
|
|
133
|
-
throw std::runtime_error("no ArrayBuffer attached");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
bool isTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj) {
|
|
138
|
-
auto jsVal =
|
|
139
|
-
runtime.global()
|
|
140
|
-
.getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
|
|
141
|
-
.asObject(runtime)
|
|
142
|
-
.getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
|
|
143
|
-
.asObject(runtime)
|
|
144
|
-
.asFunction(runtime)
|
|
145
|
-
.callWithThis(runtime, runtime.global(),
|
|
146
|
-
{jsi::Value(runtime, jsObj)});
|
|
147
|
-
if (jsVal.isBool()) {
|
|
148
|
-
return jsVal.getBool();
|
|
149
|
-
} else {
|
|
150
|
-
throw std::runtime_error("value is not a boolean");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
MGLTypedArrayBase getTypedArray(jsi::Runtime &runtime,
|
|
155
|
-
const jsi::Object &jsObj) {
|
|
156
|
-
auto jsVal =
|
|
157
|
-
runtime.global()
|
|
158
|
-
.getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
|
|
159
|
-
.asObject(runtime)
|
|
160
|
-
.getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
|
|
161
|
-
.asObject(runtime)
|
|
162
|
-
.asFunction(runtime)
|
|
163
|
-
.callWithThis(runtime, runtime.global(),
|
|
164
|
-
{jsi::Value(runtime, jsObj)});
|
|
165
|
-
if (jsVal.isBool()) {
|
|
166
|
-
return MGLTypedArrayBase(runtime, jsObj);
|
|
167
|
-
} else {
|
|
168
|
-
throw std::runtime_error("value is not a boolean");
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
std::vector<uint8_t> arrayBufferToVector(jsi::Runtime &runtime,
|
|
173
|
-
jsi::Object &jsObj) {
|
|
174
|
-
if (!jsObj.isArrayBuffer(runtime)) {
|
|
175
|
-
throw std::runtime_error("Object is not an ArrayBuffer");
|
|
176
|
-
}
|
|
177
|
-
auto jsArrayBuffer = jsObj.getArrayBuffer(runtime);
|
|
178
|
-
|
|
179
|
-
uint8_t *dataBlock = jsArrayBuffer.data(runtime);
|
|
180
|
-
size_t blockSize =
|
|
181
|
-
jsArrayBuffer
|
|
182
|
-
.getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength))
|
|
183
|
-
.asNumber();
|
|
184
|
-
return std::vector<uint8_t>(dataBlock, dataBlock + blockSize);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
void arrayBufferUpdate(jsi::Runtime &runtime, jsi::ArrayBuffer &buffer,
|
|
188
|
-
std::vector<uint8_t> data, size_t offset) {
|
|
189
|
-
uint8_t *dataBlock = buffer.data(runtime);
|
|
190
|
-
size_t blockSize = buffer.size(runtime);
|
|
191
|
-
if (data.size() > blockSize) {
|
|
192
|
-
throw jsi::JSError(runtime, "ArrayBuffer is to small to fit data");
|
|
193
|
-
}
|
|
194
|
-
std::copy(data.begin(), data.end(), dataBlock + offset);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
template <MGLTypedArrayKind T>
|
|
198
|
-
MGLTypedArray<T>::MGLTypedArray(jsi::Runtime &runtime, size_t size)
|
|
199
|
-
: MGLTypedArrayBase(runtime, size, T) {}
|
|
200
|
-
|
|
201
|
-
template <MGLTypedArrayKind T>
|
|
202
|
-
MGLTypedArray<T>::MGLTypedArray(jsi::Runtime &runtime,
|
|
203
|
-
std::vector<ContentType<T>> data)
|
|
204
|
-
: MGLTypedArrayBase(runtime, data.size(), T) {
|
|
205
|
-
update(runtime, data);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
template <MGLTypedArrayKind T>
|
|
209
|
-
MGLTypedArray<T>::MGLTypedArray(MGLTypedArrayBase &&base)
|
|
210
|
-
: MGLTypedArrayBase(std::move(base)) {}
|
|
211
|
-
|
|
212
|
-
template <MGLTypedArrayKind T>
|
|
213
|
-
std::vector<ContentType<T>> MGLTypedArray<T>::toVector(jsi::Runtime &runtime) {
|
|
214
|
-
auto start = reinterpret_cast<ContentType<T> *>(
|
|
215
|
-
getBuffer(runtime).data(runtime) + byteOffset(runtime));
|
|
216
|
-
auto end = start + size(runtime);
|
|
217
|
-
return std::vector<ContentType<T>>(start, end);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
template <MGLTypedArrayKind T>
|
|
221
|
-
void MGLTypedArray<T>::update(jsi::Runtime &runtime,
|
|
222
|
-
const std::vector<ContentType<T>> &data) {
|
|
223
|
-
if (data.size() != size(runtime)) {
|
|
224
|
-
throw jsi::JSError(
|
|
225
|
-
runtime,
|
|
226
|
-
"TypedArray can only be updated with a vector of the same size");
|
|
227
|
-
}
|
|
228
|
-
uint8_t *rawData = getBuffer(runtime).data(runtime) + byteOffset(runtime);
|
|
229
|
-
std::copy(data.begin(), data.end(),
|
|
230
|
-
reinterpret_cast<ContentType<T> *>(rawData));
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const jsi::PropNameID &PropNameIDCache::getConstructorNameProp(
|
|
234
|
-
jsi::Runtime &runtime, MGLTypedArrayKind kind) {
|
|
235
|
-
switch (kind) {
|
|
236
|
-
case MGLTypedArrayKind::Int8Array:
|
|
237
|
-
return get(runtime, Prop::Int8Array);
|
|
238
|
-
case MGLTypedArrayKind::Int16Array:
|
|
239
|
-
return get(runtime, Prop::Int16Array);
|
|
240
|
-
case MGLTypedArrayKind::Int32Array:
|
|
241
|
-
return get(runtime, Prop::Int32Array);
|
|
242
|
-
case MGLTypedArrayKind::Uint8Array:
|
|
243
|
-
return get(runtime, Prop::Uint8Array);
|
|
244
|
-
case MGLTypedArrayKind::Uint8ClampedArray:
|
|
245
|
-
return get(runtime, Prop::Uint8ClampedArray);
|
|
246
|
-
case MGLTypedArrayKind::Uint16Array:
|
|
247
|
-
return get(runtime, Prop::Uint16Array);
|
|
248
|
-
case MGLTypedArrayKind::Uint32Array:
|
|
249
|
-
return get(runtime, Prop::Uint32Array);
|
|
250
|
-
case MGLTypedArrayKind::Float32Array:
|
|
251
|
-
return get(runtime, Prop::Float32Array);
|
|
252
|
-
case MGLTypedArrayKind::Float64Array:
|
|
253
|
-
return get(runtime, Prop::Float64Array);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
jsi::PropNameID PropNameIDCache::createProp(jsi::Runtime &runtime, Prop prop) {
|
|
258
|
-
auto create = [&](const std::string &propName) {
|
|
259
|
-
return jsi::PropNameID::forUtf8(runtime, propName);
|
|
260
|
-
};
|
|
261
|
-
switch (prop) {
|
|
262
|
-
case Prop::Buffer:
|
|
263
|
-
return create("buffer");
|
|
264
|
-
case Prop::Constructor:
|
|
265
|
-
return create("constructor");
|
|
266
|
-
case Prop::Name:
|
|
267
|
-
return create("name");
|
|
268
|
-
case Prop::Proto:
|
|
269
|
-
return create("__proto__");
|
|
270
|
-
case Prop::Length:
|
|
271
|
-
return create("length");
|
|
272
|
-
case Prop::ByteLength:
|
|
273
|
-
return create("byteLength");
|
|
274
|
-
case Prop::ByteOffset:
|
|
275
|
-
return create("byteOffset");
|
|
276
|
-
case Prop::IsView:
|
|
277
|
-
return create("isView");
|
|
278
|
-
case Prop::ArrayBuffer:
|
|
279
|
-
return create("ArrayBuffer");
|
|
280
|
-
case Prop::Int8Array:
|
|
281
|
-
return create("Int8Array");
|
|
282
|
-
case Prop::Int16Array:
|
|
283
|
-
return create("Int16Array");
|
|
284
|
-
case Prop::Int32Array:
|
|
285
|
-
return create("Int32Array");
|
|
286
|
-
case Prop::Uint8Array:
|
|
287
|
-
return create("Uint8Array");
|
|
288
|
-
case Prop::Uint8ClampedArray:
|
|
289
|
-
return create("Uint8ClampedArray");
|
|
290
|
-
case Prop::Uint16Array:
|
|
291
|
-
return create("Uint16Array");
|
|
292
|
-
case Prop::Uint32Array:
|
|
293
|
-
return create("Uint32Array");
|
|
294
|
-
case Prop::Float32Array:
|
|
295
|
-
return create("Float32Array");
|
|
296
|
-
case Prop::Float64Array:
|
|
297
|
-
return create("Float64Array");
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
std::unordered_map<std::string, MGLTypedArrayKind> nameToKindMap = {
|
|
302
|
-
{"Int8Array", MGLTypedArrayKind::Int8Array},
|
|
303
|
-
{"Int16Array", MGLTypedArrayKind::Int16Array},
|
|
304
|
-
{"Int32Array", MGLTypedArrayKind::Int32Array},
|
|
305
|
-
{"Uint8Array", MGLTypedArrayKind::Uint8Array},
|
|
306
|
-
{"Uint8ClampedArray", MGLTypedArrayKind::Uint8ClampedArray},
|
|
307
|
-
{"Uint16Array", MGLTypedArrayKind::Uint16Array},
|
|
308
|
-
{"Uint32Array", MGLTypedArrayKind::Uint32Array},
|
|
309
|
-
{"Float32Array", MGLTypedArrayKind::Float32Array},
|
|
310
|
-
{"Float64Array", MGLTypedArrayKind::Float64Array},
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
MGLTypedArrayKind getTypedArrayKindForName(const std::string &name) {
|
|
314
|
-
return nameToKindMap.at(name);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
template class MGLTypedArray<MGLTypedArrayKind::Int8Array>;
|
|
318
|
-
template class MGLTypedArray<MGLTypedArrayKind::Int16Array>;
|
|
319
|
-
template class MGLTypedArray<MGLTypedArrayKind::Int32Array>;
|
|
320
|
-
template class MGLTypedArray<MGLTypedArrayKind::Uint8Array>;
|
|
321
|
-
template class MGLTypedArray<MGLTypedArrayKind::Uint8ClampedArray>;
|
|
322
|
-
template class MGLTypedArray<MGLTypedArrayKind::Uint16Array>;
|
|
323
|
-
template class MGLTypedArray<MGLTypedArrayKind::Uint32Array>;
|
|
324
|
-
template class MGLTypedArray<MGLTypedArrayKind::Float32Array>;
|
|
325
|
-
template class MGLTypedArray<MGLTypedArrayKind::Float64Array>;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// TypedArray.h
|
|
3
|
-
// react-native-quick-crypto
|
|
4
|
-
//
|
|
5
|
-
// Created by Marc Rousavy on 31.10.21.
|
|
6
|
-
// Originally created by Expo (expo-gl)
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#pragma once
|
|
10
|
-
|
|
11
|
-
#include <jsi/jsi.h>
|
|
12
|
-
|
|
13
|
-
#include <utility>
|
|
14
|
-
#include <vector>
|
|
15
|
-
|
|
16
|
-
namespace jsi = facebook::jsi;
|
|
17
|
-
|
|
18
|
-
enum class MGLTypedArrayKind {
|
|
19
|
-
Int8Array,
|
|
20
|
-
Int16Array,
|
|
21
|
-
Int32Array,
|
|
22
|
-
Uint8Array,
|
|
23
|
-
Uint8ClampedArray,
|
|
24
|
-
Uint16Array,
|
|
25
|
-
Uint32Array,
|
|
26
|
-
Float32Array,
|
|
27
|
-
Float64Array,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
template <MGLTypedArrayKind T>
|
|
31
|
-
class MGLTypedArray;
|
|
32
|
-
|
|
33
|
-
template <MGLTypedArrayKind T>
|
|
34
|
-
struct typedArrayTypeMap;
|
|
35
|
-
template <>
|
|
36
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Int8Array> {
|
|
37
|
-
typedef int8_t type;
|
|
38
|
-
};
|
|
39
|
-
template <>
|
|
40
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Int16Array> {
|
|
41
|
-
typedef int16_t type;
|
|
42
|
-
};
|
|
43
|
-
template <>
|
|
44
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Int32Array> {
|
|
45
|
-
typedef int32_t type;
|
|
46
|
-
};
|
|
47
|
-
template <>
|
|
48
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Uint8Array> {
|
|
49
|
-
typedef uint8_t type;
|
|
50
|
-
};
|
|
51
|
-
template <>
|
|
52
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Uint8ClampedArray> {
|
|
53
|
-
typedef uint8_t type;
|
|
54
|
-
};
|
|
55
|
-
template <>
|
|
56
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Uint16Array> {
|
|
57
|
-
typedef uint16_t type;
|
|
58
|
-
};
|
|
59
|
-
template <>
|
|
60
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Uint32Array> {
|
|
61
|
-
typedef uint32_t type;
|
|
62
|
-
};
|
|
63
|
-
template <>
|
|
64
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Float32Array> {
|
|
65
|
-
typedef float type;
|
|
66
|
-
};
|
|
67
|
-
template <>
|
|
68
|
-
struct typedArrayTypeMap<MGLTypedArrayKind::Float64Array> {
|
|
69
|
-
typedef double type;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
void invalidateJsiPropNameIDCache();
|
|
73
|
-
|
|
74
|
-
class MGLTypedArrayBase : public jsi::Object {
|
|
75
|
-
public:
|
|
76
|
-
template <MGLTypedArrayKind T>
|
|
77
|
-
using ContentType = typename typedArrayTypeMap<T>::type;
|
|
78
|
-
|
|
79
|
-
MGLTypedArrayBase(jsi::Runtime &, size_t, MGLTypedArrayKind);
|
|
80
|
-
MGLTypedArrayBase(jsi::Runtime &, const jsi::Object &);
|
|
81
|
-
MGLTypedArrayBase(MGLTypedArrayBase &&) = default;
|
|
82
|
-
MGLTypedArrayBase &operator=(MGLTypedArrayBase &&) = default;
|
|
83
|
-
|
|
84
|
-
MGLTypedArrayKind getKind(jsi::Runtime &runtime) const;
|
|
85
|
-
|
|
86
|
-
template <MGLTypedArrayKind T>
|
|
87
|
-
MGLTypedArray<T> get(jsi::Runtime &runtime) const &;
|
|
88
|
-
template <MGLTypedArrayKind T>
|
|
89
|
-
MGLTypedArray<T> get(jsi::Runtime &runtime) &&;
|
|
90
|
-
template <MGLTypedArrayKind T>
|
|
91
|
-
MGLTypedArray<T> as(jsi::Runtime &runtime) const &;
|
|
92
|
-
template <MGLTypedArrayKind T>
|
|
93
|
-
MGLTypedArray<T> as(jsi::Runtime &runtime) &&;
|
|
94
|
-
|
|
95
|
-
size_t size(jsi::Runtime &runtime) const;
|
|
96
|
-
size_t length(jsi::Runtime &runtime) const;
|
|
97
|
-
size_t byteLength(jsi::Runtime &runtime) const;
|
|
98
|
-
size_t byteOffset(jsi::Runtime &runtime) const;
|
|
99
|
-
bool hasBuffer(jsi::Runtime &runtime) const;
|
|
100
|
-
|
|
101
|
-
std::vector<uint8_t> toVector(jsi::Runtime &runtime);
|
|
102
|
-
jsi::ArrayBuffer getBuffer(jsi::Runtime &runtime) const;
|
|
103
|
-
|
|
104
|
-
private:
|
|
105
|
-
template <MGLTypedArrayKind>
|
|
106
|
-
friend class MGLTypedArray;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
bool isTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj);
|
|
110
|
-
MGLTypedArrayBase getTypedArray(jsi::Runtime &runtime,
|
|
111
|
-
const jsi::Object &jsObj);
|
|
112
|
-
|
|
113
|
-
std::vector<uint8_t> arrayBufferToVector(jsi::Runtime &runtime,
|
|
114
|
-
jsi::Object &jsObj);
|
|
115
|
-
void arrayBufferUpdate(jsi::Runtime &runtime, jsi::ArrayBuffer &buffer,
|
|
116
|
-
std::vector<uint8_t> data, size_t offset);
|
|
117
|
-
|
|
118
|
-
template <MGLTypedArrayKind T>
|
|
119
|
-
class MGLTypedArray : public MGLTypedArrayBase {
|
|
120
|
-
public:
|
|
121
|
-
MGLTypedArray(jsi::Runtime &runtime, size_t size);
|
|
122
|
-
MGLTypedArray(jsi::Runtime &runtime, std::vector<ContentType<T>> data);
|
|
123
|
-
explicit MGLTypedArray(MGLTypedArrayBase &&base);
|
|
124
|
-
explicit MGLTypedArray(MGLTypedArray &&) = default;
|
|
125
|
-
MGLTypedArray &operator=(MGLTypedArray &&) = default;
|
|
126
|
-
|
|
127
|
-
std::vector<ContentType<T>> toVector(jsi::Runtime &runtime);
|
|
128
|
-
void update(jsi::Runtime &runtime, const std::vector<ContentType<T>> &data);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
template <MGLTypedArrayKind T>
|
|
132
|
-
MGLTypedArray<T> MGLTypedArrayBase::get(jsi::Runtime &runtime) const & {
|
|
133
|
-
assert(getKind(runtime) == T);
|
|
134
|
-
(void)runtime; // when assert is disabled we need to mark this as used
|
|
135
|
-
return MGLTypedArray<T>(
|
|
136
|
-
jsi::Value(runtime, jsi::Value(runtime, *this).asObject(runtime)));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
template <MGLTypedArrayKind T>
|
|
140
|
-
MGLTypedArray<T> MGLTypedArrayBase::get(jsi::Runtime &runtime) && {
|
|
141
|
-
assert(getKind(runtime) == T);
|
|
142
|
-
(void)runtime; // when assert is disabled we need to mark this as used
|
|
143
|
-
return MGLTypedArray<T>(std::move(*this));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
template <MGLTypedArrayKind T>
|
|
147
|
-
MGLTypedArray<T> MGLTypedArrayBase::as(jsi::Runtime &runtime) const & {
|
|
148
|
-
if (getKind(runtime) != T) {
|
|
149
|
-
throw jsi::JSError(runtime, "Object is not a MGLTypedArray");
|
|
150
|
-
}
|
|
151
|
-
return get<T>(runtime);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
template <MGLTypedArrayKind T>
|
|
155
|
-
MGLTypedArray<T> MGLTypedArrayBase::as(jsi::Runtime &runtime) && {
|
|
156
|
-
if (getKind(runtime) != T) {
|
|
157
|
-
throw jsi::JSError(runtime, "Object is not a MGLTypedArray");
|
|
158
|
-
}
|
|
159
|
-
return std::move(*this).get<T>(runtime);
|
|
160
|
-
}
|