blob: 769a83a98aff0dbc46bd64eeed72e6f5f3cf7c28 [file] [log] [blame]
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301#pragma once
2
3#include "keyword_vpd_types.hpp"
4
5namespace vpd
6{
7namespace keyword
8{
9namespace parser
10{
11
12/**
13 * @class KeywordVpdParser
14 * @brief Implements parser for Keyword VPD
15 *
16 * KeywordVpdParser object must be constructed by passing in
17 * Keyword VPD in binary format. To parse the VPD, call the
18 * kwVpdParser() method. The kwVpdParser() method returns
19 * a map of keyword-value pairs.
20 *
21 * Following is the algorithm used to parse Keyword VPD data:
22 * 1) Validate if the first byte is 'largeResourceIdentifierString'.
23 * 2) Validate the byte after the description is 'vendor defined large resource
24 * type tag'.
25 * 3) For each keyword-value pairs :
26 * 3.1) Parse the 2 byte length keyword and emplace it in the map as 'key'.
27 * 3.2) Parse over the value bytes corresponding to the keyword and
28 * emplace it in the map as 'value' for the key inserted in 3.1.
29 * 4) Validate the byte before checksum byte is 'small resource type end tag'.
30 * 5) Validate the checksum.
31 * 6) Validate the 'small resource type last end tag'.
32 * 7) Return the keyword-value map.
33 */
34
35class KeywordVpdParser
36{
37 public:
38 KeywordVpdParser() = delete;
39 KeywordVpdParser(const KeywordVpdParser&) = delete;
40 KeywordVpdParser(KeywordVpdParser&&) = delete;
41 ~KeywordVpdParser() = default;
42
43 /**
44 * @brief Move Constructor
45 *
46 * Move kwVpdVector to parser object's kwVpdVector
47 */
48 KeywordVpdParser(Binary&& kwVpdVector) :
49 keywordVpdVector(std::move(kwVpdVector))
50 {
51 }
52
53 /**
54 * @brief Parse the keyword VPD binary data.
55 *
56 * Calls the sub functions to emplace the
57 * keyword-value pairs in map and to validate
58 * certain tags and checksum data.
59 *
60 * @return map of keyword:value
61 */
62 KeywordVpdMap parseKwVpd();
63
64 private:
65 Binary::iterator checkSumStart; //!< Pointer to the start byte from where
66 //!< the checksum need to be calculated
67 Binary::iterator checkSumEnd; //!< Pointer to the end byte until which the
68 //!< checksum need to be calculated
69 Binary::iterator kwVpdIterator; //!< Iterator to parse the vector
70 Binary keywordVpdVector; //!< Vector which stores keyword VPD data
71
72 /**
73 * @brief Validate the large resource identifier string
74 */
75 void validateLargeResourceIdentifierString();
76
77 /**
78 * @brief Validate the type of keyword VPD
79 *
80 * @return integer representing the type of kw VPD.
81 */
82 int validateTheTypeOfKwVpd();
83
84 /**
85 * @brief Parsing keyword-value pairs and emplace into Map.
86 *
87 * @return map of keyword:value
88 */
89 KeywordVpdMap kwValParser();
90
91 /**
92 * @brief Validate small resource type end tag
93 */
94 void validateSmallResourceTypeEnd();
95
96 /**
97 * @brief Validate checksum.
98 *
99 * Finding the 2's complement of sum of all the
100 * keywords,values and large resource identifier string.
101 */
102 void validateChecksum();
103
104 /**
105 * @brief Validate small resource type last end tag
106 */
107 void validateSmallResourceTypeLastEnd();
108
109 /**
110 * @brief Get the size of the keyword
111 *
112 * @return one byte length size data
113 */
114 size_t getKwDataSize();
115
116 /**
117 * @brief Check for iterator Out of Bound exception
118 *
119 * Check if no.of elements from (begining of the vector) to (iterator +
120 * incVar) is lesser than or equal to the total no.of elements in the
121 * vector. This check is performed before the advancement of the iterator.
122 *
123 * @param[incVar] - no.of positions the iterator is going to be iterated
124 */
125 void itrOutOfBoundCheck(uint8_t incVar);
126};
127} // namespace parser
128} // namespace keyword
129} // namespace vpd