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

Method parse

valdi/src/valdi/runtime/Resources/AssetCatalog.cpp:62–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62Result<Ref<AssetCatalog>> AssetCatalog::parse(const Byte* data, size_t length) {
63 ValdiArchive archive(data, data + length);
64
65 auto entries = archive.getEntries();
66 if (!entries) {
67 return entries.moveError();
68 }
69
70 std::vector<AssetSpecs> assets;
71
72 for (const auto& entry : entries.value()) {
73 auto parser = Parser(entry.data, entry.data + entry.dataLength);
74
75 AssetData assetData;
76 if (entry.dataLength >= sizeof(AssetData)) {
77 auto result = parser.parseStruct<AssetData>();
78 if (!result) {
79 return result.moveError();
80 }
81 std::memcpy(&assetData, reinterpret_cast<const void*>(result.value()), sizeof(AssetData));
82 } else {
83 auto result = parser.parseStruct<AssetDataLegacy>();
84 if (!result) {
85 return result.moveError();
86 }
87 std::memcpy(&assetData, reinterpret_cast<const void*>(result.value()), sizeof(AssetDataLegacy));
88 assetData.type = kAssetTypeImage;
89 }
90
91 auto type = AssetSpecsType::UNKNOWN;
92 if (assetData.type == kAssetTypeImage) {
93 type = AssetSpecsType::IMAGE;
94 } else if (assetData.type == kAssetTypeFont) {
95 type = AssetSpecsType::FONT;
96 }
97
98 assets.emplace_back(
99 entry.filePath, static_cast<int>(assetData.width), static_cast<int>(assetData.height), type);
100 }
101
102 return Valdi::makeShared<AssetCatalog>(std::move(assets));
103}
104
105const std::vector<AssetSpecs>& AssetCatalog::getAssets() const {
106 return _assets;

Callers

nothing calls this directly

Calls 3

valueMethod · 0.65
ParserClass · 0.50
getEntriesMethod · 0.45

Tested by

no test coverage detected