Deepak Kodihalli | cb7f2d4 | 2019-06-19 13:25:31 +0530 | [diff] [blame] | 1 | #include "bios_table.hpp" |
| 2 | |
| 3 | #include <fstream> |
| 4 | |
| 5 | namespace pldm |
| 6 | { |
| 7 | |
| 8 | namespace responder |
| 9 | { |
| 10 | |
| 11 | namespace bios |
| 12 | { |
| 13 | |
| 14 | BIOSTable::BIOSTable(const char* filePath) : filePath(filePath) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | bool BIOSTable::isEmpty() const noexcept |
| 19 | { |
| 20 | bool empty = false; |
| 21 | try |
| 22 | { |
| 23 | empty = fs::is_empty(filePath); |
| 24 | } |
| 25 | catch (fs::filesystem_error& e) |
| 26 | { |
| 27 | return true; |
| 28 | } |
| 29 | return empty; |
| 30 | } |
| 31 | |
| 32 | void BIOSTable::store(const Table& table) |
| 33 | { |
| 34 | std::ofstream stream(filePath.string(), std::ios::out | std::ios::binary); |
| 35 | stream.write(reinterpret_cast<const char*>(table.data()), table.size()); |
| 36 | } |
| 37 | |
| 38 | void BIOSTable::load(Response& response) const |
| 39 | { |
| 40 | auto currSize = response.size(); |
| 41 | auto fileSize = fs::file_size(filePath); |
| 42 | response.resize(currSize + fileSize); |
| 43 | std::ifstream stream(filePath.string(), std::ios::in | std::ios::binary); |
| 44 | stream.read(reinterpret_cast<char*>(response.data() + currSize), fileSize); |
| 45 | } |
| 46 | |
| 47 | } // namespace bios |
| 48 | } // namespace responder |
| 49 | } // namespace pldm |