MCPcopy Create free account
hub / github.com/Snapchat/Valdi / notifyAssetConsumer

Method notifyAssetConsumer

valdi/src/valdi/runtime/Resources/AssetsManager.cpp:625–659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

623}
624
625void AssetsManager::notifyAssetConsumer(AssetsManagerTransaction& transaction,
626 const AssetKey& assetKey,
627 const Ref<ManagedAsset>& managedAsset,
628 const Ref<AssetConsumer>& assetConsumer,
629 const Ref<LoadedAsset>& loadedAsset,
630 const std::optional<Error>& error) {
631 auto observable = managedAsset->getObservable();
632 assetConsumer->setNotified(true);
633 transaction.releaseLock();
634
635 std::optional<StringBox> errorStringBox;
636 if (error) {
637 auto errorString = error.value().toStringBox();
638 VALDI_WARN(_logger, "Notifying error for consumer of Asset '{}': {}", assetKey, errorString);
639 errorStringBox = {errorString};
640 }
641
642 // Default to sending the asset as-is
643 Value assetValue = Value(loadedAsset);
644
645 // Convert BytesAsset to ValueTypedArray for proper JavaScript marshalling
646 // Only do this for assets loaded with BYTES output type
647 if (loadedAsset != nullptr && assetConsumer->getOutputType() == snap::valdi_core::AssetOutputType::Bytes) {
648 // This was loaded as a bytes asset, try to get bytes content
649 auto bytesContentResult = loadedAsset->getBytesContent();
650 if (bytesContentResult) {
651 // Wrap in ValueTypedArray so JS receives a Uint8Array
652 assetValue = Value(makeShared<ValueTypedArray>(TypedArrayType::Uint8Array, bytesContentResult.value()));
653 }
654 }
655
656 assetConsumer->getObserver()->onLoad(observable, assetValue, errorStringBox);
657
658 transaction.acquireLock();
659}
660
661void AssetsManager::updateConsumerRequestHandler(const Ref<AssetConsumer>& assetConsumer,
662 const Ref<AssetLoaderRequestHandler>& request) {

Callers

nothing calls this directly

Calls 10

getObservableMethod · 0.80
setNotifiedMethod · 0.80
acquireLockMethod · 0.80
releaseLockMethod · 0.65
valueMethod · 0.65
onLoadMethod · 0.65
ValueClass · 0.50
toStringBoxMethod · 0.45
getOutputTypeMethod · 0.45
getBytesContentMethod · 0.45

Tested by

no test coverage detected