blob: 74a896949be61b4466cae17498e4ee1248170506 [file] [log] [blame]
Deepak Kodihalli810c9de2016-11-22 11:42:51 -06001#include <exception>
2#include <iostream>
3#include <iterator>
4#include "impl.hpp"
5
6namespace openpower
7{
8namespace vpd
9{
10namespace parser
11{
12
13namespace offsets
14{
15
16enum Offsets
17{
18 VHDR = 17
19};
20
21}
22
23namespace lengths
24{
25
26enum Lengths
27{
28 RECORD_NAME = 4,
29 RECORD_MIN = 44,
30};
31
32}
33
34void Impl::checkHeader() const
35{
36 if (vpd.empty() || (lengths::RECORD_MIN > vpd.size()))
37 {
38 throw std::runtime_error("Malformed VPD");
39 }
40 else
41 {
42 auto iterator = vpd.cbegin();
43 std::advance(iterator, offsets::VHDR);
44 auto stop = std::next(iterator, lengths::RECORD_NAME);
45 std::string record(iterator, stop);
46 if ("VHDR" != record)
47 {
48 throw std::runtime_error("VHDR record not found");
49 }
50 }
51}
52
53} // namespace parser
54} // namespace vpd
55} // namespace openpower