blob: df2c8dd18849536932a7c9ba9fc418246c7c439f [file] [log] [blame]
Deepak Kodihallicb7f2d42019-06-19 13:25:31 +05301#include "bios_table.hpp"
2
3#include <fstream>
4
5namespace pldm
6{
7
8namespace responder
9{
10
11namespace bios
12{
13
14BIOSTable::BIOSTable(const char* filePath) : filePath(filePath)
15{
16}
17
18bool 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
32void 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
38void 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