#include "assets_manager.h"
#include <android/asset_manager.h>

void AssetsManager::Init(AAssetManager *asset_manager)
{
    m_asset_manager = asset_manager;
}

std::vector<uint8_t> AssetsManager::ReadAll(const std::string &filename)
{
    if (AAsset* asset = AAssetManager_open(m_asset_manager,
        filename.c_str(), AASSET_MODE_BUFFER))
    {
        const auto size = AAsset_getLength(asset);
        auto buffer = std::vector<uint8_t>(size);
        AAsset_read(asset, buffer.data(), size);
        AAsset_close(asset);
        return buffer;
    }
    return {};
}

AAssetManager *AssetsManager::Native()
{
    return m_asset_manager;
}
