diff --git a/interop/src/cpp/ani/convertors-ani.h b/interop/src/cpp/ani/convertors-ani.h index 0923edaa07be31e983c6c7f6a5a67395f28cbb2d..8d50abcc89607ba0ac5d038391670ad9d33fc56b 100644 --- a/interop/src/cpp/ani/convertors-ani.h +++ b/interop/src/cpp/ani/convertors-ani.h @@ -52,14 +52,14 @@ inline static void printErrorStack() { } } -#define CHECK_ANI_FATAL(result) \ -do { \ - ani_status res = (result); \ - if (res != ANI_OK) { \ - printErrorStack(); \ - INTEROP_FATAL("ANI function failed (status: %d) at " __FILE__ ": %d", res, __LINE__); \ - } \ -} \ +#define CHECK_ANI_FATAL(result) \ +do { \ + ani_status ___res___ = (result); \ + if (___res___ != ANI_OK) { \ + printErrorStack(); \ + INTEROP_FATAL("ANI function failed (status: %d) at " __FILE__ ": %d", ___res___, __LINE__); \ + } \ +} \ while (0) template @@ -158,22 +158,19 @@ struct InteropTypeConverter { template<> struct InteropTypeConverter { - using InteropType = ani_fixedarray_byte; + using InteropType = ani_arraybuffer; static inline KInteropBuffer convertFrom(ani_env* env, InteropType value) { - if (value == nullptr) return KInteropBuffer(); - ani_size length = 0; - CHECK_ANI_FATAL(env->FixedArray_GetLength(value, &length)); - KByte* data = new KByte[length]; - CHECK_ANI_FATAL(env->FixedArray_GetRegion_Byte(value, 0, length, (ani_byte*)data)); - KInteropBuffer result = { 0 }; - result.data = data; - result.length = length; - return result; + void* data {}; + size_t len {}; + CHECK_ANI_FATAL(env->ArrayBuffer_GetInfo(value, &data, &len)); + return {static_cast(len), data, 0, nullptr}; } + static inline InteropType convertTo(ani_env* env, KInteropBuffer value) { - ani_fixedarray_byte result; - CHECK_ANI_FATAL(env->FixedArray_New_Byte(value.length, &result)); - CHECK_ANI_FATAL(env->FixedArray_SetRegion_Byte(result, 0, value.length, reinterpret_cast(value.data))); + void* data {}; + ani_arraybuffer result; + CHECK_ANI_FATAL(env->CreateArrayBuffer(value.length, &data, &result)); + interop_memcpy(data, value.length, value.data, value.length); value.dispose(value.resourceId); return result; }