| 61 | } |
| 62 | |
| 63 | Valdi::Result<Valdi::BytesView> ResourceLoader::loadModuleContent(const Valdi::StringBox& module) { |
| 64 | if (_shouldDeferModuleLoadToJava) { |
| 65 | auto modulePathJava = toJavaObject(JavaEnv(), module); |
| 66 | Valdi::SimpleExceptionTracker exceptionTracker; |
| 67 | Valdi::Marshaller errorHolder(exceptionTracker); |
| 68 | |
| 69 | auto moduleData = _getCustomModuleDataMethod.call( |
| 70 | _localResourceResolver.toObject(), modulePathJava, reinterpret_cast<jlong>(&errorHolder)); |
| 71 | |
| 72 | if (errorHolder.size() > 0) { |
| 73 | return errorHolder.getOrUndefined(-1).getError(); |
| 74 | } |
| 75 | |
| 76 | if (!moduleData.isNull()) { |
| 77 | return toByteArray(JavaEnv(), reinterpret_cast<jbyteArray>(moduleData.getUnsafeObject())); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | #ifdef __ANDROID__ |
| 82 | auto* asset = AAssetManager_open(_assetManager, module.getCStr(), AASSET_MODE_BUFFER); |
| 83 | if (asset == nullptr) { |
| 84 | return Valdi::Error("Unable to open asset"); |
| 85 | } |
| 86 | auto managedAsset = Valdi::makeShared<ManagedAsset>(asset); |
| 87 | |
| 88 | const auto* buffer = AAsset_getBuffer(asset); |
| 89 | auto length = AAsset_getLength(asset); |
| 90 | |
| 91 | return Valdi::BytesView(managedAsset, reinterpret_cast<const Valdi::Byte*>(buffer), static_cast<size_t>(length)); |
| 92 | #else |
| 93 | return Valdi::Error("Not implemented"); |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | Valdi::StringBox ResourceLoader::resolveLocalAssetURL(const Valdi::StringBox& moduleName, |
| 98 | const Valdi::StringBox& resourcePath) { |