Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "parser_interface.hpp" |
| 4 | #include "types.hpp" |
| 5 | |
| 6 | namespace vpd |
| 7 | { |
| 8 | |
| 9 | /** |
| 10 | * @brief Concrete class to implement Keyword VPD parsing |
| 11 | * |
| 12 | * The class inherits ParserInterface class and overrides the parser |
| 13 | * functionality to implement parsing logic for Keyword VPD format. |
| 14 | */ |
| 15 | class KeywordVpdParser : public ParserInterface |
| 16 | { |
| 17 | public: |
| 18 | KeywordVpdParser() = delete; |
| 19 | KeywordVpdParser(const KeywordVpdParser&) = delete; |
| 20 | KeywordVpdParser(KeywordVpdParser&&) = delete; |
| 21 | ~KeywordVpdParser() = default; |
| 22 | |
| 23 | /** |
| 24 | * @brief Constructor |
| 25 | * |
| 26 | * @param kwVpdVector - move it to object's m_keywordVpdVector |
| 27 | */ |
| 28 | KeywordVpdParser(const types::BinaryVector& kwVpdVector) : |
| 29 | m_keywordVpdVector(kwVpdVector), |
| 30 | m_vpdIterator(m_keywordVpdVector.begin()) |
| 31 | {} |
| 32 | |
| 33 | /** |
| 34 | * @brief A wrapper function to parse the keyword VPD binary data. |
| 35 | * |
| 36 | * It validates certain tags and checksum data, calls helper function |
| 37 | * to parse and emplace the data as keyword-value pairs in KeywordVpdMap. |
| 38 | * |
| 39 | * @throw DataException - VPD is not valid |
| 40 | * @return map of keyword:value |
| 41 | */ |
| 42 | types::VPDMapVariant parse(); |
| 43 | |
| 44 | private: |
| 45 | /** |
| 46 | * @brief Parse the VPD data and emplace them as pair into the Map. |
| 47 | * |
| 48 | * @throw DataException - VPD data size is 0, check VPD |
| 49 | * @return map of keyword:value |
| 50 | */ |
| 51 | types::KeywordVpdMap populateVpdMap(); |
| 52 | |
| 53 | /** |
| 54 | * @brief Validate checksum. |
| 55 | * |
| 56 | * Finding the 2's complement of sum of all the |
| 57 | * keywords,values and large resource identifier string. |
| 58 | * |
| 59 | * @param[in] i_checkSumStart - VPD iterator pointing at checksum start |
| 60 | * value |
| 61 | * @param[in] i_checkSumEnd - VPD iterator pointing at checksum end value |
| 62 | * @throw DataException - checksum invalid, check VPD |
| 63 | */ |
| 64 | void validateChecksum(types::BinaryVector::const_iterator i_checkSumStart, |
| 65 | types::BinaryVector::const_iterator i_checkSumEnd); |
| 66 | |
| 67 | /** |
| 68 | * @brief It reads 2 bytes from current VPD pointer |
| 69 | * |
| 70 | * @return 2 bytes of VPD data |
| 71 | */ |
| 72 | inline size_t getKwDataSize() |
| 73 | { |
| 74 | return (*(m_vpdIterator + 1) << 8 | *m_vpdIterator); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @brief Check for given number of bytes validity |
| 79 | * |
| 80 | * Check if number of elements from (begining of the vector) to (iterator + |
| 81 | * numberOfBytes) is lesser than or equal to the total no.of elements in |
| 82 | * the vector. This check is performed before advancement of the iterator. |
| 83 | * |
| 84 | * @param[in] numberOfBytes - no.of positions the iterator is going to be |
| 85 | * iterated |
| 86 | * |
| 87 | * @throw DataException - Truncated VPD data, check VPD. |
| 88 | */ |
| 89 | void checkNextBytesValidity(uint8_t numberOfBytes); |
| 90 | |
| 91 | /*Vector of keyword VPD data*/ |
| 92 | const types::BinaryVector& m_keywordVpdVector; |
| 93 | |
| 94 | /*Iterator to VPD data*/ |
| 95 | types::BinaryVector::const_iterator m_vpdIterator; |
| 96 | }; |
| 97 | } // namespace vpd |