@dittolive/ditto 4.4.5 → 4.5.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/DittoReactNative.podspec +27 -0
- package/README.md +68 -51
- package/node/ditto.cjs.js +1639 -851
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/ditto.linux-arm.node +0 -0
- package/node/ditto.linux-x64.node +0 -0
- package/node/ditto.win32-x64.node +0 -0
- package/node/transports.darwin-arm64.node +0 -0
- package/node/transports.darwin-x64.node +0 -0
- package/package.json +34 -38
- package/react-native/android/CMakeLists.txt +37 -0
- package/react-native/android/build.gradle +203 -0
- package/react-native/android/cpp-adapter.cpp +254 -0
- package/react-native/android/gradle.properties +5 -0
- package/react-native/android/src/main/AndroidManifest.xml +4 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +85 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKPackage.java +28 -0
- package/react-native/boost/boost/assert.hpp +85 -0
- package/react-native/boost/boost/config/abi/borland_prefix.hpp +27 -0
- package/react-native/boost/boost/config/abi/borland_suffix.hpp +12 -0
- package/react-native/boost/boost/config/abi/msvc_prefix.hpp +22 -0
- package/react-native/boost/boost/config/abi/msvc_suffix.hpp +8 -0
- package/react-native/boost/boost/config/abi_prefix.hpp +25 -0
- package/react-native/boost/boost/config/abi_suffix.hpp +25 -0
- package/react-native/boost/boost/config/assert_cxx03.hpp +211 -0
- package/react-native/boost/boost/config/assert_cxx11.hpp +209 -0
- package/react-native/boost/boost/config/assert_cxx14.hpp +47 -0
- package/react-native/boost/boost/config/assert_cxx17.hpp +62 -0
- package/react-native/boost/boost/config/assert_cxx20.hpp +59 -0
- package/react-native/boost/boost/config/assert_cxx98.hpp +23 -0
- package/react-native/boost/boost/config/auto_link.hpp +525 -0
- package/react-native/boost/boost/config/compiler/borland.hpp +339 -0
- package/react-native/boost/boost/config/compiler/clang.hpp +366 -0
- package/react-native/boost/boost/config/compiler/clang_version.hpp +83 -0
- package/react-native/boost/boost/config/compiler/codegear.hpp +385 -0
- package/react-native/boost/boost/config/compiler/comeau.hpp +59 -0
- package/react-native/boost/boost/config/compiler/common_edg.hpp +183 -0
- package/react-native/boost/boost/config/compiler/compaq_cxx.hpp +19 -0
- package/react-native/boost/boost/config/compiler/cray.hpp +446 -0
- package/react-native/boost/boost/config/compiler/diab.hpp +26 -0
- package/react-native/boost/boost/config/compiler/digitalmars.hpp +143 -0
- package/react-native/boost/boost/config/compiler/gcc.hpp +383 -0
- package/react-native/boost/boost/config/compiler/gcc_xml.hpp +114 -0
- package/react-native/boost/boost/config/compiler/greenhills.hpp +28 -0
- package/react-native/boost/boost/config/compiler/hp_acc.hpp +149 -0
- package/react-native/boost/boost/config/compiler/intel.hpp +577 -0
- package/react-native/boost/boost/config/compiler/kai.hpp +33 -0
- package/react-native/boost/boost/config/compiler/metrowerks.hpp +198 -0
- package/react-native/boost/boost/config/compiler/mpw.hpp +140 -0
- package/react-native/boost/boost/config/compiler/nvcc.hpp +61 -0
- package/react-native/boost/boost/config/compiler/pathscale.hpp +138 -0
- package/react-native/boost/boost/config/compiler/pgi.hpp +23 -0
- package/react-native/boost/boost/config/compiler/sgi_mipspro.hpp +29 -0
- package/react-native/boost/boost/config/compiler/sunpro_cc.hpp +222 -0
- package/react-native/boost/boost/config/compiler/vacpp.hpp +186 -0
- package/react-native/boost/boost/config/compiler/visualc.hpp +391 -0
- package/react-native/boost/boost/config/compiler/xlcpp.hpp +299 -0
- package/react-native/boost/boost/config/compiler/xlcpp_zos.hpp +173 -0
- package/react-native/boost/boost/config/detail/cxx_composite.hpp +203 -0
- package/react-native/boost/boost/config/detail/posix_features.hpp +95 -0
- package/react-native/boost/boost/config/detail/select_compiler_config.hpp +157 -0
- package/react-native/boost/boost/config/detail/select_platform_config.hpp +147 -0
- package/react-native/boost/boost/config/detail/select_stdlib_config.hpp +121 -0
- package/react-native/boost/boost/config/detail/suffix.hpp +1294 -0
- package/react-native/boost/boost/config/header_deprecated.hpp +26 -0
- package/react-native/boost/boost/config/helper_macros.hpp +37 -0
- package/react-native/boost/boost/config/no_tr1/cmath.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/complex.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/functional.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/memory.hpp +28 -0
- package/react-native/boost/boost/config/no_tr1/utility.hpp +28 -0
- package/react-native/boost/boost/config/platform/aix.hpp +33 -0
- package/react-native/boost/boost/config/platform/amigaos.hpp +15 -0
- package/react-native/boost/boost/config/platform/beos.hpp +26 -0
- package/react-native/boost/boost/config/platform/bsd.hpp +83 -0
- package/react-native/boost/boost/config/platform/cloudabi.hpp +18 -0
- package/react-native/boost/boost/config/platform/cray.hpp +18 -0
- package/react-native/boost/boost/config/platform/cygwin.hpp +71 -0
- package/react-native/boost/boost/config/platform/haiku.hpp +31 -0
- package/react-native/boost/boost/config/platform/hpux.hpp +87 -0
- package/react-native/boost/boost/config/platform/irix.hpp +31 -0
- package/react-native/boost/boost/config/platform/linux.hpp +106 -0
- package/react-native/boost/boost/config/platform/macos.hpp +87 -0
- package/react-native/boost/boost/config/platform/qnxnto.hpp +31 -0
- package/react-native/boost/boost/config/platform/solaris.hpp +31 -0
- package/react-native/boost/boost/config/platform/symbian.hpp +97 -0
- package/react-native/boost/boost/config/platform/vms.hpp +25 -0
- package/react-native/boost/boost/config/platform/vxworks.hpp +422 -0
- package/react-native/boost/boost/config/platform/wasm.hpp +23 -0
- package/react-native/boost/boost/config/platform/win32.hpp +90 -0
- package/react-native/boost/boost/config/platform/zos.hpp +32 -0
- package/react-native/boost/boost/config/pragma_message.hpp +31 -0
- package/react-native/boost/boost/config/requires_threads.hpp +92 -0
- package/react-native/boost/boost/config/stdlib/dinkumware.hpp +324 -0
- package/react-native/boost/boost/config/stdlib/libcomo.hpp +93 -0
- package/react-native/boost/boost/config/stdlib/libcpp.hpp +180 -0
- package/react-native/boost/boost/config/stdlib/libstdcpp3.hpp +482 -0
- package/react-native/boost/boost/config/stdlib/modena.hpp +79 -0
- package/react-native/boost/boost/config/stdlib/msl.hpp +98 -0
- package/react-native/boost/boost/config/stdlib/roguewave.hpp +208 -0
- package/react-native/boost/boost/config/stdlib/sgi.hpp +168 -0
- package/react-native/boost/boost/config/stdlib/stlport.hpp +258 -0
- package/react-native/boost/boost/config/stdlib/vacpp.hpp +74 -0
- package/react-native/boost/boost/config/stdlib/xlcpp_zos.hpp +61 -0
- package/react-native/boost/boost/config/user.hpp +133 -0
- package/react-native/boost/boost/config/warning_disable.hpp +47 -0
- package/react-native/boost/boost/config/workaround.hpp +305 -0
- package/react-native/boost/boost/config.hpp +67 -0
- package/react-native/boost/boost/cstdint.hpp +556 -0
- package/react-native/boost/boost/intrusive_ptr.hpp +18 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count.hpp +103 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc.hpp +79 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_atomic.hpp +63 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_gcc_x86.hpp +88 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_nt.hpp +66 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_pt.hpp +104 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_spin.hpp +69 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_std_atomic.hpp +67 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_sync.hpp +72 -0
- package/react-native/boost/boost/smart_ptr/detail/atomic_count_win32.hpp +70 -0
- package/react-native/boost/boost/smart_ptr/detail/local_counted_base.hpp +148 -0
- package/react-native/boost/boost/smart_ptr/detail/local_sp_deleter.hpp +91 -0
- package/react-native/boost/boost/smart_ptr/detail/operator_bool.hpp +64 -0
- package/react-native/boost/boost/smart_ptr/detail/requires_cxx11.hpp +23 -0
- package/react-native/boost/boost/smart_ptr/detail/shared_count.hpp +707 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_convertible.hpp +92 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base.hpp +92 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp +163 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_aix.hpp +152 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_cw_ppc.hpp +185 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp +148 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ia64.hpp +170 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp +200 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp +194 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_sparc.hpp +179 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp +186 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_nt.hpp +119 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_pt.hpp +147 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp +174 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_spin.hpp +141 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp +147 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_sync.hpp +165 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp +163 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_base_w32.hpp +140 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_counted_impl.hpp +309 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_disable_deprecated.hpp +40 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_forward.hpp +52 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_has_gcc_intrinsics.hpp +27 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_has_sync_intrinsics.hpp +69 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_interlocked.hpp +173 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_noexcept.hpp +48 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_nullptr_t.hpp +45 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_obsolete.hpp +32 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_pause.hpp +51 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_sleep.hpp +104 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_thread_yield.hpp +100 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_typeinfo_.hpp +58 -0
- package/react-native/boost/boost/smart_ptr/detail/sp_win32_sleep.hpp +49 -0
- package/react-native/boost/boost/smart_ptr/intrusive_ptr.hpp +409 -0
- package/react-native/boost/boost/smart_ptr/intrusive_ref_counter.hpp +188 -0
- package/react-native/cpp/include/Attachment.h +16 -0
- package/react-native/cpp/include/Authentication.h +23 -0
- package/react-native/cpp/include/Collection.h +13 -0
- package/react-native/cpp/include/DQL.h +21 -0
- package/react-native/cpp/include/Document.h +17 -0
- package/react-native/cpp/include/Identity.h +17 -0
- package/react-native/cpp/include/Lifecycle.h +16 -0
- package/react-native/cpp/include/LiveQuery.h +17 -0
- package/react-native/cpp/include/Logger.h +22 -0
- package/react-native/cpp/include/Misc.h +26 -0
- package/react-native/cpp/include/Presence.h +14 -0
- package/react-native/cpp/include/RetainableState.h +24 -0
- package/react-native/cpp/include/SmallPeerInfo.h +17 -0
- package/react-native/cpp/include/Transports.h +25 -0
- package/react-native/cpp/include/TypedArray.hpp +167 -0
- package/react-native/cpp/include/Utils.h +61 -0
- package/react-native/cpp/include/main.h +10 -0
- package/react-native/cpp/src/Attachment.cpp +86 -0
- package/react-native/cpp/src/Authentication.cpp +224 -0
- package/react-native/cpp/src/Collection.cpp +54 -0
- package/react-native/cpp/src/DQL.cpp +254 -0
- package/react-native/cpp/src/Document.cpp +146 -0
- package/react-native/cpp/src/Identity.cpp +123 -0
- package/react-native/cpp/src/Lifecycle.cpp +75 -0
- package/react-native/cpp/src/LiveQuery.cpp +64 -0
- package/react-native/cpp/src/Logger.cpp +200 -0
- package/react-native/cpp/src/Misc.cpp +271 -0
- package/react-native/cpp/src/Presence.cpp +77 -0
- package/react-native/cpp/src/RetainableState.cpp +15 -0
- package/react-native/cpp/src/SmallPeerInfo.cpp +108 -0
- package/react-native/cpp/src/Transports.cpp +270 -0
- package/react-native/cpp/src/TypedArray.cpp +303 -0
- package/react-native/cpp/src/Utils.cpp +138 -0
- package/react-native/cpp/src/main.cpp +149 -0
- package/react-native/dittoffi/dittoffi.h +4698 -0
- package/react-native/dittoffi/ifaddrs.cpp +385 -0
- package/react-native/dittoffi/ifaddrs.h +206 -0
- package/react-native/ios/DittoRNSDK.h +7 -0
- package/react-native/ios/DittoRNSDK.mm +107 -0
- package/react-native/ios/YeetJSIUtils.h +60 -0
- package/react-native/ios/YeetJSIUtils.mm +196 -0
- package/react-native/lib/commonjs/ditto.rn.js +93 -0
- package/react-native/lib/commonjs/ditto.rn.js.map +1 -0
- package/react-native/lib/commonjs/index.js +14 -0
- package/react-native/lib/commonjs/index.js.map +1 -0
- package/react-native/lib/module/ditto.rn.js +83 -0
- package/react-native/lib/module/ditto.rn.js.map +1 -0
- package/react-native/lib/module/index.js +13 -0
- package/react-native/lib/module/index.js.map +1 -0
- package/react-native/lib/typescript/ditto.rn.d.ts +15 -0
- package/react-native/lib/typescript/ditto.rn.d.ts.map +1 -0
- package/react-native/lib/typescript/index.d.ts +1 -0
- package/react-native/lib/typescript/index.d.ts.map +1 -0
- package/react-native/scripts/ruby/include_local_boost.rb +78 -0
- package/react-native/src/ditto.rn.ts +91 -0
- package/react-native/src/environment/environment.fallback.ts +4 -0
- package/react-native/src/index.ts +26 -0
- package/react-native/src/sources/@cbor-redux.ts +2 -0
- package/react-native/src/sources/@ditto.core.ts +1 -0
- package/react-native/src/sources/@environment.ts +2 -0
- package/react-native/src/sources/attachment-fetch-event.ts +54 -0
- package/react-native/src/sources/attachment-fetcher-manager.ts +129 -0
- package/react-native/src/sources/attachment-fetcher.ts +124 -0
- package/react-native/src/sources/attachment-token.ts +48 -0
- package/react-native/src/sources/attachment.ts +59 -0
- package/react-native/src/sources/augment.ts +89 -0
- package/react-native/src/sources/authenticator.ts +314 -0
- package/react-native/src/sources/base-pending-cursor-operation.ts +237 -0
- package/react-native/src/sources/base-pending-id-specific-operation.ts +109 -0
- package/react-native/src/sources/bridge.ts +549 -0
- package/react-native/src/sources/build-time-constants.ts +4 -0
- package/react-native/src/sources/cbor.ts +35 -0
- package/react-native/src/sources/collection-interface.ts +67 -0
- package/react-native/src/sources/collection.ts +212 -0
- package/react-native/src/sources/collections-event.ts +99 -0
- package/react-native/src/sources/counter.ts +77 -0
- package/react-native/src/sources/ditto.ts +945 -0
- package/react-native/src/sources/document-id.ts +159 -0
- package/react-native/src/sources/document-path.ts +303 -0
- package/react-native/src/sources/document.ts +192 -0
- package/react-native/src/sources/epilogue.ts +24 -0
- package/react-native/src/sources/error-codes.ts +52 -0
- package/react-native/src/sources/error.ts +203 -0
- package/react-native/src/sources/essentials.ts +53 -0
- package/react-native/src/sources/ffi-error.ts +117 -0
- package/react-native/src/sources/ffi.ts +1972 -0
- package/react-native/src/sources/identity.ts +163 -0
- package/react-native/src/sources/init.ts +70 -0
- package/react-native/src/sources/internal.ts +113 -0
- package/react-native/src/sources/keep-alive.ts +69 -0
- package/react-native/src/sources/key-path.ts +195 -0
- package/react-native/src/sources/live-query-event.ts +208 -0
- package/react-native/src/sources/live-query-manager.ts +101 -0
- package/react-native/src/sources/live-query.ts +164 -0
- package/react-native/src/sources/logger.ts +196 -0
- package/react-native/src/sources/observer-manager.ts +175 -0
- package/react-native/src/sources/observer.ts +77 -0
- package/react-native/src/sources/pending-collections-operation.ts +232 -0
- package/react-native/src/sources/pending-cursor-operation.ts +218 -0
- package/react-native/src/sources/pending-id-specific-operation.ts +216 -0
- package/react-native/src/sources/presence-manager.ts +160 -0
- package/react-native/src/sources/presence.ts +238 -0
- package/react-native/src/sources/query-result-item.ts +116 -0
- package/react-native/src/sources/query-result.ts +55 -0
- package/react-native/src/sources/register.ts +92 -0
- package/react-native/src/sources/small-peer-info.ts +176 -0
- package/react-native/src/sources/static-tcp-client.ts +6 -0
- package/react-native/src/sources/store-observer.ts +176 -0
- package/react-native/src/sources/store.ts +365 -0
- package/react-native/src/sources/subscription-manager.ts +98 -0
- package/react-native/src/sources/subscription.ts +88 -0
- package/react-native/src/sources/sync-subscription.ts +90 -0
- package/react-native/src/sources/sync.ts +495 -0
- package/react-native/src/sources/test-helpers.ts +24 -0
- package/react-native/src/sources/transport-conditions-manager.ts +104 -0
- package/react-native/src/sources/transport-config.ts +428 -0
- package/react-native/src/sources/update-result.ts +66 -0
- package/react-native/src/sources/update-results-map.ts +57 -0
- package/react-native/src/sources/websocket-client.ts +6 -0
- package/react-native/src/sources/write-transaction-collection.ts +122 -0
- package/react-native/src/sources/write-transaction-pending-cursor-operation.ts +101 -0
- package/react-native/src/sources/write-transaction-pending-id-specific-operation.ts +72 -0
- package/react-native/src/sources/write-transaction.ts +119 -0
- package/react-native.config.js +9 -0
- package/types/ditto.d.ts +1230 -798
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
#include "Utils.h"
|
|
2
|
+
|
|
3
|
+
#include <Transports.h>
|
|
4
|
+
#include <dittoffi.h>
|
|
5
|
+
|
|
6
|
+
namespace sharedjsi
|
|
7
|
+
{
|
|
8
|
+
|
|
9
|
+
Function ditto_sdk_transports_error_new(Runtime &runtime)
|
|
10
|
+
{
|
|
11
|
+
return Function::createFromHostFunction(runtime,
|
|
12
|
+
PropNameID::forAscii(runtime,
|
|
13
|
+
STRINGIFIED_FUNC_NAME()),
|
|
14
|
+
0,
|
|
15
|
+
[](Runtime &runtime,
|
|
16
|
+
const Value &thisValue,
|
|
17
|
+
const Value *arguments,
|
|
18
|
+
size_t count) -> Value
|
|
19
|
+
{
|
|
20
|
+
DittoSdkTransportsError_t *outError = ::ditto_sdk_transports_error_new();
|
|
21
|
+
return cPointerToJSPointerObject<DittoSdkTransportsError_t>(runtime, outError);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Function ditto_sdk_transports_init(Runtime &runtime)
|
|
26
|
+
{
|
|
27
|
+
return Function::createFromHostFunction(runtime,
|
|
28
|
+
PropNameID::forAscii(runtime,
|
|
29
|
+
STRINGIFIED_FUNC_NAME()),
|
|
30
|
+
0,
|
|
31
|
+
[](Runtime &runtime,
|
|
32
|
+
const Value &thisValue,
|
|
33
|
+
const Value *arguments,
|
|
34
|
+
size_t count) -> Value
|
|
35
|
+
{
|
|
36
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[0]);
|
|
37
|
+
return ::ditto_sdk_transports_init(outError);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Function ditto_sdk_transports_error_value(Runtime &runtime)
|
|
42
|
+
{
|
|
43
|
+
return Function::createFromHostFunction(runtime,
|
|
44
|
+
PropNameID::forAscii(runtime,
|
|
45
|
+
STRINGIFIED_FUNC_NAME()),
|
|
46
|
+
0,
|
|
47
|
+
[](Runtime &runtime,
|
|
48
|
+
const Value &thisValue,
|
|
49
|
+
const Value *arguments,
|
|
50
|
+
size_t count) -> Value
|
|
51
|
+
{
|
|
52
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[0]);
|
|
53
|
+
DittoSdkTransportsError_t error = ::ditto_sdk_transports_error_value(outError);
|
|
54
|
+
|
|
55
|
+
switch (error)
|
|
56
|
+
{
|
|
57
|
+
case DITTO_SDK_TRANSPORTS_ERROR_NONE:
|
|
58
|
+
return String::createFromUtf8(runtime, "None");
|
|
59
|
+
case DITTO_SDK_TRANSPORTS_ERROR_GENERIC:
|
|
60
|
+
return String::createFromUtf8(runtime, "Generic");
|
|
61
|
+
case DITTO_SDK_TRANSPORTS_ERROR_UNAVAILABLE:
|
|
62
|
+
return String::createFromUtf8(runtime, "Unavailable");
|
|
63
|
+
default:
|
|
64
|
+
throw "Unimplemented error value";
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Function ditto_sdk_transports_error_free(Runtime &runtime)
|
|
70
|
+
{
|
|
71
|
+
return Function::createFromHostFunction(runtime,
|
|
72
|
+
PropNameID::forAscii(runtime,
|
|
73
|
+
STRINGIFIED_FUNC_NAME()),
|
|
74
|
+
0,
|
|
75
|
+
[](Runtime &runtime,
|
|
76
|
+
const Value &thisValue,
|
|
77
|
+
const Value *arguments,
|
|
78
|
+
size_t count) -> Value
|
|
79
|
+
{
|
|
80
|
+
::ditto_sdk_transports_error_free(jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[0]));
|
|
81
|
+
return Value();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Function ditto_sdk_transports_ble_is_available(Runtime &runtime)
|
|
86
|
+
{
|
|
87
|
+
return Function::createFromHostFunction(runtime,
|
|
88
|
+
PropNameID::forAscii(runtime,
|
|
89
|
+
STRINGIFIED_FUNC_NAME()),
|
|
90
|
+
0,
|
|
91
|
+
[](Runtime &runtime,
|
|
92
|
+
const Value &thisValue,
|
|
93
|
+
const Value *arguments,
|
|
94
|
+
size_t count) -> Value
|
|
95
|
+
{
|
|
96
|
+
return ::ditto_sdk_transports_ble_is_available(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Function ditto_sdk_transports_ble_create(Runtime &runtime)
|
|
101
|
+
{
|
|
102
|
+
return Function::createFromHostFunction(runtime,
|
|
103
|
+
PropNameID::forAscii(runtime,
|
|
104
|
+
STRINGIFIED_FUNC_NAME()),
|
|
105
|
+
0,
|
|
106
|
+
[](Runtime &runtime,
|
|
107
|
+
const Value &thisValue,
|
|
108
|
+
const Value *arguments,
|
|
109
|
+
size_t count) -> Value
|
|
110
|
+
{
|
|
111
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
112
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[1]);
|
|
113
|
+
void *res = ::ditto_sdk_transports_ble_create(ditto, outError);
|
|
114
|
+
void *transports = static_cast<void *>(res);
|
|
115
|
+
return cPointerToJSPointerObject<void>(runtime, transports);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
Function ditto_sdk_transports_ble_destroy(Runtime &runtime)
|
|
120
|
+
{
|
|
121
|
+
return Function::createFromHostFunction(runtime,
|
|
122
|
+
PropNameID::forAscii(runtime,
|
|
123
|
+
STRINGIFIED_FUNC_NAME()),
|
|
124
|
+
0,
|
|
125
|
+
[](Runtime &runtime,
|
|
126
|
+
const Value &thisValue,
|
|
127
|
+
const Value *arguments,
|
|
128
|
+
size_t count) -> Value
|
|
129
|
+
{
|
|
130
|
+
void *ble = jsPointerObjectToCPointer<void>(runtime, arguments[0]);
|
|
131
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[1]);
|
|
132
|
+
return ::ditto_sdk_transports_ble_destroy(ble, outError);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
Function ditto_sdk_transports_lan_is_available(Runtime &runtime)
|
|
137
|
+
{
|
|
138
|
+
return Function::createFromHostFunction(runtime,
|
|
139
|
+
PropNameID::forAscii(runtime,
|
|
140
|
+
STRINGIFIED_FUNC_NAME()),
|
|
141
|
+
0,
|
|
142
|
+
[](Runtime &runtime,
|
|
143
|
+
const Value &thisValue,
|
|
144
|
+
const Value *arguments,
|
|
145
|
+
size_t count) -> Value
|
|
146
|
+
{
|
|
147
|
+
return ::ditto_sdk_transports_lan_is_available(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
Function ditto_sdk_transports_lan_create(Runtime &runtime)
|
|
152
|
+
{
|
|
153
|
+
return Function::createFromHostFunction(runtime,
|
|
154
|
+
PropNameID::forAscii(runtime,
|
|
155
|
+
STRINGIFIED_FUNC_NAME()),
|
|
156
|
+
0,
|
|
157
|
+
[](Runtime &runtime,
|
|
158
|
+
const Value &thisValue,
|
|
159
|
+
const Value *arguments,
|
|
160
|
+
size_t count) -> Value
|
|
161
|
+
{
|
|
162
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
163
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[1]);
|
|
164
|
+
void *res = ::ditto_sdk_transports_lan_create(ditto, outError);
|
|
165
|
+
void *transports = static_cast<void *>(res);
|
|
166
|
+
return cPointerToJSPointerObject<void>(runtime, transports);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
Function ditto_sdk_transports_lan_destroy(Runtime &runtime)
|
|
171
|
+
{
|
|
172
|
+
return Function::createFromHostFunction(runtime,
|
|
173
|
+
PropNameID::forAscii(runtime,
|
|
174
|
+
STRINGIFIED_FUNC_NAME()),
|
|
175
|
+
0,
|
|
176
|
+
[](Runtime &runtime,
|
|
177
|
+
const Value &thisValue,
|
|
178
|
+
const Value *arguments,
|
|
179
|
+
size_t count) -> Value
|
|
180
|
+
{
|
|
181
|
+
void *lan = jsPointerObjectToCPointer<void>(runtime, arguments[0]);
|
|
182
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[1]);
|
|
183
|
+
return ::ditto_sdk_transports_lan_destroy(lan, outError);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
Function ditto_sdk_transports_awdl_is_available(Runtime &runtime)
|
|
188
|
+
{
|
|
189
|
+
return Function::createFromHostFunction(runtime,
|
|
190
|
+
PropNameID::forAscii(runtime,
|
|
191
|
+
STRINGIFIED_FUNC_NAME()),
|
|
192
|
+
0,
|
|
193
|
+
[](Runtime &runtime,
|
|
194
|
+
const Value &thisValue,
|
|
195
|
+
const Value *arguments,
|
|
196
|
+
size_t count) -> Value
|
|
197
|
+
{
|
|
198
|
+
return ::ditto_sdk_transports_awdl_is_available(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
Function ditto_sdk_transports_awdl_create(Runtime &runtime)
|
|
203
|
+
{
|
|
204
|
+
return Function::createFromHostFunction(runtime,
|
|
205
|
+
PropNameID::forAscii(runtime,
|
|
206
|
+
STRINGIFIED_FUNC_NAME()),
|
|
207
|
+
0,
|
|
208
|
+
[](Runtime &runtime,
|
|
209
|
+
const Value &thisValue,
|
|
210
|
+
const Value *arguments,
|
|
211
|
+
size_t count) -> Value
|
|
212
|
+
{
|
|
213
|
+
CDitto_t *ditto = jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]);
|
|
214
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[1]);
|
|
215
|
+
void *res = ::ditto_sdk_transports_awdl_create(ditto, outError);
|
|
216
|
+
void *transports = static_cast<void *>(res);
|
|
217
|
+
return cPointerToJSPointerObject<void>(runtime, transports);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
Function ditto_sdk_transports_awdl_destroy(Runtime &runtime)
|
|
222
|
+
{
|
|
223
|
+
return Function::createFromHostFunction(runtime,
|
|
224
|
+
PropNameID::forAscii(runtime,
|
|
225
|
+
STRINGIFIED_FUNC_NAME()),
|
|
226
|
+
0,
|
|
227
|
+
[](Runtime &runtime,
|
|
228
|
+
const Value &thisValue,
|
|
229
|
+
const Value *arguments,
|
|
230
|
+
size_t count) -> Value
|
|
231
|
+
{
|
|
232
|
+
void *awdl = jsPointerObjectToCPointer<void>(runtime, arguments[0]);
|
|
233
|
+
DittoSdkTransportsError_t *outError = jsPointerObjectToCPointer<DittoSdkTransportsError_t>(runtime, arguments[1]);
|
|
234
|
+
return ::ditto_sdk_transports_awdl_destroy(awdl, outError);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
Function ditto_add_multicast_transport(Runtime &runtime)
|
|
239
|
+
{
|
|
240
|
+
return Function::createFromHostFunction(runtime,
|
|
241
|
+
PropNameID::forAscii(runtime,
|
|
242
|
+
STRINGIFIED_FUNC_NAME()),
|
|
243
|
+
0,
|
|
244
|
+
[](Runtime &runtime,
|
|
245
|
+
const Value &thisValue,
|
|
246
|
+
const Value *arguments,
|
|
247
|
+
size_t count) -> Value
|
|
248
|
+
{
|
|
249
|
+
::ditto_add_multicast_transport(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
250
|
+
return Value();
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
Function ditto_remove_multicast_transport(Runtime &runtime)
|
|
255
|
+
{
|
|
256
|
+
return Function::createFromHostFunction(runtime,
|
|
257
|
+
PropNameID::forAscii(runtime,
|
|
258
|
+
STRINGIFIED_FUNC_NAME()),
|
|
259
|
+
0,
|
|
260
|
+
[](Runtime &runtime,
|
|
261
|
+
const Value &thisValue,
|
|
262
|
+
const Value *arguments,
|
|
263
|
+
size_t count) -> Value
|
|
264
|
+
{
|
|
265
|
+
::ditto_remove_multicast_transport(jsPointerObjectToCPointer<CDitto_t>(runtime, arguments[0]));
|
|
266
|
+
return Value();
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#include "TypedArray.hpp"
|
|
2
|
+
|
|
3
|
+
#include <unordered_map>
|
|
4
|
+
#include <stdexcept>
|
|
5
|
+
|
|
6
|
+
template <TypedArrayKind T>
|
|
7
|
+
using ContentType = typename typedArrayTypeMap<T>::type;
|
|
8
|
+
|
|
9
|
+
enum class Prop {
|
|
10
|
+
Buffer, // "buffer"
|
|
11
|
+
Constructor, // "constructor"
|
|
12
|
+
Name, // "name"
|
|
13
|
+
Proto, // "__proto__"
|
|
14
|
+
Length, // "length"
|
|
15
|
+
ByteLength, // "byteLength"
|
|
16
|
+
ByteOffset, // "offset"
|
|
17
|
+
IsView, // "isView"
|
|
18
|
+
ArrayBuffer, // "ArrayBuffer"
|
|
19
|
+
Int8Array, // "Int8Array"
|
|
20
|
+
Int16Array, // "Int16Array"
|
|
21
|
+
Int32Array, // "Int32Array"
|
|
22
|
+
Uint8Array, // "Uint8Array"
|
|
23
|
+
Uint8ClampedArray, // "Uint8ClampedArray"
|
|
24
|
+
Uint16Array, // "Uint16Array"
|
|
25
|
+
Uint32Array, // "Uint32Array"
|
|
26
|
+
Float32Array, // "Float32Array"
|
|
27
|
+
Float64Array, // "Float64Array"
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class PropNameIDCache {
|
|
31
|
+
public:
|
|
32
|
+
const jsi::PropNameID &get(jsi::Runtime &runtime, Prop prop) {
|
|
33
|
+
auto key = reinterpret_cast<uintptr_t>(&runtime);
|
|
34
|
+
if (this->props.find(key) == this->props.end()) {
|
|
35
|
+
this->props[key] = std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>>();
|
|
36
|
+
}
|
|
37
|
+
if (!this->props[key][prop]) {
|
|
38
|
+
this->props[key][prop] = std::make_unique<jsi::PropNameID>(createProp(runtime, prop));
|
|
39
|
+
}
|
|
40
|
+
return *(this->props[key][prop]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const jsi::PropNameID &getConstructorNameProp(jsi::Runtime &runtime, TypedArrayKind kind);
|
|
44
|
+
|
|
45
|
+
void invalidate(uintptr_t key) {
|
|
46
|
+
if (props.find(key) != props.end()) {
|
|
47
|
+
props[key].clear();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private:
|
|
52
|
+
std::unordered_map<uintptr_t, std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>>> props;
|
|
53
|
+
|
|
54
|
+
jsi::PropNameID createProp(jsi::Runtime &runtime, Prop prop);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
PropNameIDCache propNameIDCache;
|
|
58
|
+
|
|
59
|
+
InvalidateCacheOnDestroy::InvalidateCacheOnDestroy(jsi::Runtime &runtime) {
|
|
60
|
+
key = reinterpret_cast<uintptr_t>(&runtime);
|
|
61
|
+
}
|
|
62
|
+
InvalidateCacheOnDestroy::~InvalidateCacheOnDestroy() {
|
|
63
|
+
propNameIDCache.invalidate(key);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
TypedArrayKind getTypedArrayKindForName(const std::string &name);
|
|
67
|
+
|
|
68
|
+
TypedArrayBase::TypedArrayBase(jsi::Runtime &runtime, size_t size, TypedArrayKind kind)
|
|
69
|
+
: TypedArrayBase(
|
|
70
|
+
runtime,
|
|
71
|
+
runtime.global()
|
|
72
|
+
.getProperty(runtime, propNameIDCache.getConstructorNameProp(runtime, kind))
|
|
73
|
+
.asObject(runtime)
|
|
74
|
+
.asFunction(runtime)
|
|
75
|
+
.callAsConstructor(runtime, {static_cast<double>(size)})
|
|
76
|
+
.asObject(runtime)) {}
|
|
77
|
+
|
|
78
|
+
TypedArrayBase::TypedArrayBase(jsi::Runtime &runtime, const jsi::Object &obj)
|
|
79
|
+
: jsi::Object(jsi::Value(runtime, obj).asObject(runtime)) {}
|
|
80
|
+
|
|
81
|
+
TypedArrayKind TypedArrayBase::getKind(jsi::Runtime &runtime) const {
|
|
82
|
+
auto constructorName = this->getProperty(runtime, propNameIDCache.get(runtime, Prop::Constructor))
|
|
83
|
+
.asObject(runtime)
|
|
84
|
+
.getProperty(runtime, propNameIDCache.get(runtime, Prop::Name))
|
|
85
|
+
.asString(runtime)
|
|
86
|
+
.utf8(runtime);
|
|
87
|
+
return getTypedArrayKindForName(constructorName);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
size_t TypedArrayBase::size(jsi::Runtime &runtime) const {
|
|
91
|
+
return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length)).asNumber();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
size_t TypedArrayBase::length(jsi::Runtime &runtime) const {
|
|
95
|
+
return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length)).asNumber();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
size_t TypedArrayBase::byteLength(jsi::Runtime &runtime) const {
|
|
99
|
+
return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength)).asNumber();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
size_t TypedArrayBase::byteOffset(jsi::Runtime &runtime) const {
|
|
103
|
+
return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteOffset)).asNumber();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
bool TypedArrayBase::hasBuffer(jsi::Runtime &runtime) const {
|
|
107
|
+
auto buffer = getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
|
|
108
|
+
return buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
std::vector<uint8_t> TypedArrayBase::toVector(jsi::Runtime &runtime) {
|
|
112
|
+
auto start = reinterpret_cast<uint8_t *>(getBuffer(runtime).data(runtime) + byteOffset(runtime));
|
|
113
|
+
auto end = start + byteLength(runtime);
|
|
114
|
+
return std::vector<uint8_t>(start, end);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
jsi::ArrayBuffer TypedArrayBase::getBuffer(jsi::Runtime &runtime) const {
|
|
118
|
+
auto buffer = getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
|
|
119
|
+
if (buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime)) {
|
|
120
|
+
return buffer.asObject(runtime).getArrayBuffer(runtime);
|
|
121
|
+
} else {
|
|
122
|
+
throw std::runtime_error("No ArrayBuffer attached");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
bool isTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj) {
|
|
127
|
+
auto jsVal = runtime.global()
|
|
128
|
+
.getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
|
|
129
|
+
.asObject(runtime)
|
|
130
|
+
.getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
|
|
131
|
+
.asObject(runtime)
|
|
132
|
+
.asFunction(runtime)
|
|
133
|
+
.callWithThis(runtime, runtime.global(), {jsi::Value(runtime, jsObj)});
|
|
134
|
+
if (jsVal.isBool()) {
|
|
135
|
+
return jsVal.getBool();
|
|
136
|
+
} else {
|
|
137
|
+
throw std::runtime_error("value is not a boolean");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
TypedArrayBase getTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj) {
|
|
142
|
+
auto jsVal = runtime.global()
|
|
143
|
+
.getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
|
|
144
|
+
.asObject(runtime)
|
|
145
|
+
.getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
|
|
146
|
+
.asObject(runtime)
|
|
147
|
+
.asFunction(runtime)
|
|
148
|
+
.callWithThis(runtime, runtime.global(), {jsi::Value(runtime, jsObj)});
|
|
149
|
+
if (jsVal.isBool()) {
|
|
150
|
+
return TypedArrayBase(runtime, jsObj);
|
|
151
|
+
} else {
|
|
152
|
+
throw std::runtime_error("value is not a boolean");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
std::vector<uint8_t> arrayBufferToVector(jsi::Runtime &runtime, jsi::Object &jsObj) {
|
|
157
|
+
if (!jsObj.isArrayBuffer(runtime)) {
|
|
158
|
+
throw std::runtime_error("Object is not an ArrayBuffer");
|
|
159
|
+
}
|
|
160
|
+
auto jsArrayBuffer = jsObj.getArrayBuffer(runtime);
|
|
161
|
+
|
|
162
|
+
uint8_t *dataBlock = jsArrayBuffer.data(runtime);
|
|
163
|
+
size_t blockSize =
|
|
164
|
+
jsArrayBuffer.getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength)).asNumber();
|
|
165
|
+
return std::vector<uint8_t>(dataBlock, dataBlock + blockSize);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void arrayBufferUpdate(
|
|
169
|
+
jsi::Runtime &runtime,
|
|
170
|
+
jsi::ArrayBuffer &buffer,
|
|
171
|
+
std::vector<uint8_t> data,
|
|
172
|
+
size_t offset) {
|
|
173
|
+
uint8_t *dataBlock = buffer.data(runtime);
|
|
174
|
+
size_t blockSize = buffer.size(runtime);
|
|
175
|
+
if (data.size() > blockSize) {
|
|
176
|
+
throw jsi::JSError(runtime, "ArrayBuffer is to small to fit data");
|
|
177
|
+
}
|
|
178
|
+
std::copy(data.begin(), data.end(), dataBlock + offset);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
template <TypedArrayKind T>
|
|
182
|
+
TypedArray<T>::TypedArray(jsi::Runtime &runtime, size_t size) : TypedArrayBase(runtime, size, T){};
|
|
183
|
+
|
|
184
|
+
template <TypedArrayKind T>
|
|
185
|
+
TypedArray<T>::TypedArray(jsi::Runtime &runtime, std::vector<ContentType<T>> data)
|
|
186
|
+
: TypedArrayBase(runtime, data.size(), T) {
|
|
187
|
+
update(runtime, data);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
template <TypedArrayKind T>
|
|
191
|
+
TypedArray<T>::TypedArray(TypedArrayBase &&base) : TypedArrayBase(std::move(base)) {}
|
|
192
|
+
|
|
193
|
+
template <TypedArrayKind T>
|
|
194
|
+
std::vector<ContentType<T>> TypedArray<T>::toVector(jsi::Runtime &runtime) {
|
|
195
|
+
auto start =
|
|
196
|
+
reinterpret_cast<ContentType<T> *>(getBuffer(runtime).data(runtime) + byteOffset(runtime));
|
|
197
|
+
auto end = start + size(runtime);
|
|
198
|
+
return std::vector<ContentType<T>>(start, end);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
template <TypedArrayKind T>
|
|
202
|
+
void TypedArray<T>::update(jsi::Runtime &runtime, const std::vector<ContentType<T>> &data) {
|
|
203
|
+
if (data.size() != size(runtime)) {
|
|
204
|
+
throw jsi::JSError(runtime, "TypedArray can only be updated with a vector of the same size");
|
|
205
|
+
}
|
|
206
|
+
uint8_t *rawData = getBuffer(runtime).data(runtime) + byteOffset(runtime);
|
|
207
|
+
std::copy(data.begin(), data.end(), reinterpret_cast<ContentType<T> *>(rawData));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const jsi::PropNameID &PropNameIDCache::getConstructorNameProp(
|
|
211
|
+
jsi::Runtime &runtime,
|
|
212
|
+
TypedArrayKind kind) {
|
|
213
|
+
switch (kind) {
|
|
214
|
+
case TypedArrayKind::Int8Array:
|
|
215
|
+
return get(runtime, Prop::Int8Array);
|
|
216
|
+
case TypedArrayKind::Int16Array:
|
|
217
|
+
return get(runtime, Prop::Int16Array);
|
|
218
|
+
case TypedArrayKind::Int32Array:
|
|
219
|
+
return get(runtime, Prop::Int32Array);
|
|
220
|
+
case TypedArrayKind::Uint8Array:
|
|
221
|
+
return get(runtime, Prop::Uint8Array);
|
|
222
|
+
case TypedArrayKind::Uint8ClampedArray:
|
|
223
|
+
return get(runtime, Prop::Uint8ClampedArray);
|
|
224
|
+
case TypedArrayKind::Uint16Array:
|
|
225
|
+
return get(runtime, Prop::Uint16Array);
|
|
226
|
+
case TypedArrayKind::Uint32Array:
|
|
227
|
+
return get(runtime, Prop::Uint32Array);
|
|
228
|
+
case TypedArrayKind::Float32Array:
|
|
229
|
+
return get(runtime, Prop::Float32Array);
|
|
230
|
+
case TypedArrayKind::Float64Array:
|
|
231
|
+
return get(runtime, Prop::Float64Array);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
jsi::PropNameID PropNameIDCache::createProp(jsi::Runtime &runtime, Prop prop) {
|
|
236
|
+
auto create = [&](const std::string &propName) {
|
|
237
|
+
return jsi::PropNameID::forUtf8(runtime, propName);
|
|
238
|
+
};
|
|
239
|
+
switch (prop) {
|
|
240
|
+
case Prop::Buffer:
|
|
241
|
+
return create("buffer");
|
|
242
|
+
case Prop::Constructor:
|
|
243
|
+
return create("constructor");
|
|
244
|
+
case Prop::Name:
|
|
245
|
+
return create("name");
|
|
246
|
+
case Prop::Proto:
|
|
247
|
+
return create("__proto__");
|
|
248
|
+
case Prop::Length:
|
|
249
|
+
return create("length");
|
|
250
|
+
case Prop::ByteLength:
|
|
251
|
+
return create("byteLength");
|
|
252
|
+
case Prop::ByteOffset:
|
|
253
|
+
return create("byteOffset");
|
|
254
|
+
case Prop::IsView:
|
|
255
|
+
return create("isView");
|
|
256
|
+
case Prop::ArrayBuffer:
|
|
257
|
+
return create("ArrayBuffer");
|
|
258
|
+
case Prop::Int8Array:
|
|
259
|
+
return create("Int8Array");
|
|
260
|
+
case Prop::Int16Array:
|
|
261
|
+
return create("Int16Array");
|
|
262
|
+
case Prop::Int32Array:
|
|
263
|
+
return create("Int32Array");
|
|
264
|
+
case Prop::Uint8Array:
|
|
265
|
+
return create("Uint8Array");
|
|
266
|
+
case Prop::Uint8ClampedArray:
|
|
267
|
+
return create("Uint8ClampedArray");
|
|
268
|
+
case Prop::Uint16Array:
|
|
269
|
+
return create("Uint16Array");
|
|
270
|
+
case Prop::Uint32Array:
|
|
271
|
+
return create("Uint32Array");
|
|
272
|
+
case Prop::Float32Array:
|
|
273
|
+
return create("Float32Array");
|
|
274
|
+
case Prop::Float64Array:
|
|
275
|
+
return create("Float64Array");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
std::unordered_map<std::string, TypedArrayKind> nameToKindMap = {
|
|
280
|
+
{"Int8Array", TypedArrayKind::Int8Array},
|
|
281
|
+
{"Int16Array", TypedArrayKind::Int16Array},
|
|
282
|
+
{"Int32Array", TypedArrayKind::Int32Array},
|
|
283
|
+
{"Uint8Array", TypedArrayKind::Uint8Array},
|
|
284
|
+
{"Uint8ClampedArray", TypedArrayKind::Uint8ClampedArray},
|
|
285
|
+
{"Uint16Array", TypedArrayKind::Uint16Array},
|
|
286
|
+
{"Uint32Array", TypedArrayKind::Uint32Array},
|
|
287
|
+
{"Float32Array", TypedArrayKind::Float32Array},
|
|
288
|
+
{"Float64Array", TypedArrayKind::Float64Array},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
TypedArrayKind getTypedArrayKindForName(const std::string &name) {
|
|
292
|
+
return nameToKindMap.at(name);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
template class TypedArray<TypedArrayKind::Int8Array>;
|
|
296
|
+
template class TypedArray<TypedArrayKind::Int16Array>;
|
|
297
|
+
template class TypedArray<TypedArrayKind::Int32Array>;
|
|
298
|
+
template class TypedArray<TypedArrayKind::Uint8Array>;
|
|
299
|
+
template class TypedArray<TypedArrayKind::Uint8ClampedArray>;
|
|
300
|
+
template class TypedArray<TypedArrayKind::Uint16Array>;
|
|
301
|
+
template class TypedArray<TypedArrayKind::Uint32Array>;
|
|
302
|
+
template class TypedArray<TypedArrayKind::Float32Array>;
|
|
303
|
+
template class TypedArray<TypedArrayKind::Float64Array>;
|