1c5f01b2fSopenharmony_ci// __ _____ _____ _____ 2c5f01b2fSopenharmony_ci// __| | __| | | | JSON for Modern C++ (supporting code) 3c5f01b2fSopenharmony_ci// | | |__ | | | | | | version 3.11.2 4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___| https://github.com/nlohmann/json 5c5f01b2fSopenharmony_ci// 6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> 7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT 8c5f01b2fSopenharmony_ci 9c5f01b2fSopenharmony_ci#pragma once 10c5f01b2fSopenharmony_ci 11c5f01b2fSopenharmony_ci#include <cstdint> // uint8_t 12c5f01b2fSopenharmony_ci#include <fstream> // ifstream, istreambuf_iterator, ios 13c5f01b2fSopenharmony_ci#include <vector> // vector 14c5f01b2fSopenharmony_ci 15c5f01b2fSopenharmony_cinamespace utils 16c5f01b2fSopenharmony_ci{ 17c5f01b2fSopenharmony_ci 18c5f01b2fSopenharmony_ciinline std::vector<std::uint8_t> read_binary_file(const std::string& filename) 19c5f01b2fSopenharmony_ci{ 20c5f01b2fSopenharmony_ci std::ifstream file(filename, std::ios::binary); 21c5f01b2fSopenharmony_ci file.unsetf(std::ios::skipws); 22c5f01b2fSopenharmony_ci 23c5f01b2fSopenharmony_ci file.seekg(0, std::ios::end); 24c5f01b2fSopenharmony_ci const auto size = file.tellg(); 25c5f01b2fSopenharmony_ci file.seekg(0, std::ios::beg); 26c5f01b2fSopenharmony_ci 27c5f01b2fSopenharmony_ci std::vector<std::uint8_t> byte_vector; 28c5f01b2fSopenharmony_ci byte_vector.reserve(static_cast<std::size_t>(size)); 29c5f01b2fSopenharmony_ci byte_vector.insert(byte_vector.begin(), std::istream_iterator<std::uint8_t>(file), std::istream_iterator<std::uint8_t>()); 30c5f01b2fSopenharmony_ci return byte_vector; 31c5f01b2fSopenharmony_ci} 32c5f01b2fSopenharmony_ci 33c5f01b2fSopenharmony_ci} // namespace utils 34