MCPcopy Create free account
hub / github.com/android/ndk-samples / AssetReadFile

Function AssetReadFile

teapots/textured-teapot/src/main/cpp/AssetUtil.cpp:61–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61bool AssetReadFile(AAssetManager* assetManager, std::string& assetName,
62 std::vector<uint8_t>& buf) {
63 if (!assetName.length()) return false;
64 AAsset* assetDescriptor =
65 AAssetManager_open(assetManager, assetName.c_str(), AASSET_MODE_BUFFER);
66 ASSERT(assetDescriptor, "%s does not exist in %s", assetName.c_str(),
67 __FUNCTION__);
68 size_t remaining = AAsset_getLength(assetDescriptor);
69
70 buf.resize(remaining);
71 size_t idx = 0;
72
73 while (remaining > 0) {
74 int readSize = AAsset_read(assetDescriptor, &buf[idx], remaining);
75 if (readSize < 0) {
76 LOGE("AAsset_read of %s failed", assetName.c_str());
77 return false;
78 }
79 idx += readSize;
80 remaining -= readSize;
81 }
82
83 AAsset_close(assetDescriptor);
84 return true;
85}

Callers 1

TextureMethod · 0.85

Calls 1

resizeMethod · 0.45

Tested by

no test coverage detected