151c9263fSAatir Manzur #pragma once 251c9263fSAatir Manzur 351c9263fSAatir Manzur #include "section.hpp" 451c9263fSAatir Manzur #include "stream.hpp" 551c9263fSAatir Manzur 651c9263fSAatir Manzur namespace openpower 751c9263fSAatir Manzur { 851c9263fSAatir Manzur namespace pels 951c9263fSAatir Manzur { 1051c9263fSAatir Manzur 1151c9263fSAatir Manzur /** 1251c9263fSAatir Manzur * @class UserData 1351c9263fSAatir Manzur * 1451c9263fSAatir Manzur * This represents the User Data section in a PEL. It is free form data 1551c9263fSAatir Manzur * that the creator knows the contents of. The component ID, version, 1651c9263fSAatir Manzur * and sub-type fields in the section header are used to identify the 1751c9263fSAatir Manzur * format. 1851c9263fSAatir Manzur * 1951c9263fSAatir Manzur * The Section base class handles the section header structure that every 2051c9263fSAatir Manzur * PEL section has at offset zero. 2151c9263fSAatir Manzur */ 2251c9263fSAatir Manzur class UserData : public Section 2351c9263fSAatir Manzur { 2451c9263fSAatir Manzur public: 2551c9263fSAatir Manzur UserData() = delete; 2651c9263fSAatir Manzur ~UserData() = default; 2751c9263fSAatir Manzur UserData(const UserData&) = default; 2851c9263fSAatir Manzur UserData& operator=(const UserData&) = default; 2951c9263fSAatir Manzur UserData(UserData&&) = default; 3051c9263fSAatir Manzur UserData& operator=(UserData&&) = default; 3151c9263fSAatir Manzur 3251c9263fSAatir Manzur /** 3351c9263fSAatir Manzur * @brief Constructor 3451c9263fSAatir Manzur * 3551c9263fSAatir Manzur * Fills in this class's data fields from the stream. 3651c9263fSAatir Manzur * 3751c9263fSAatir Manzur * @param[in] pel - the PEL data stream 3851c9263fSAatir Manzur */ 3951c9263fSAatir Manzur explicit UserData(Stream& pel); 4051c9263fSAatir Manzur 4151c9263fSAatir Manzur /** 4251c9263fSAatir Manzur * @brief Constructor 4351c9263fSAatir Manzur * 4451c9263fSAatir Manzur * Create a valid UserData object with the passed in data. 4551c9263fSAatir Manzur * 4651c9263fSAatir Manzur * The component ID, subtype, and version are used to identify 4751c9263fSAatir Manzur * the data to know which parser to call. 4851c9263fSAatir Manzur * 4951c9263fSAatir Manzur * @param[in] componentID - Component ID of the creator 5051c9263fSAatir Manzur * @param[in] subType - The type of user data 5151c9263fSAatir Manzur * @param[in] version - The version of the data 5251c9263fSAatir Manzur */ 5351c9263fSAatir Manzur UserData(uint16_t componentID, uint8_t subType, uint8_t version, 5451c9263fSAatir Manzur const std::vector<uint8_t>& data); 5551c9263fSAatir Manzur 5651c9263fSAatir Manzur /** 5751c9263fSAatir Manzur * @brief Flatten the section into the stream 5851c9263fSAatir Manzur * 5951c9263fSAatir Manzur * @param[in] stream - The stream to write to 6051c9263fSAatir Manzur */ 610688545bSMatt Spinler void flatten(Stream& stream) const override; 6251c9263fSAatir Manzur 6351c9263fSAatir Manzur /** 6451c9263fSAatir Manzur * @brief Returns the size of this section when flattened into a PEL 6551c9263fSAatir Manzur * 6651c9263fSAatir Manzur * @return size_t - the size of the section 6751c9263fSAatir Manzur */ flattenedSize()6851c9263fSAatir Manzur size_t flattenedSize() 6951c9263fSAatir Manzur { 7051c9263fSAatir Manzur return Section::flattenedSize() + _data.size(); 7151c9263fSAatir Manzur } 7251c9263fSAatir Manzur 7351c9263fSAatir Manzur /** 7451c9263fSAatir Manzur * @brief Returns the raw section data 7551c9263fSAatir Manzur * 7651c9263fSAatir Manzur * @return std::vector<uint8_t>& 7751c9263fSAatir Manzur */ data() const7851c9263fSAatir Manzur const std::vector<uint8_t>& data() const 7951c9263fSAatir Manzur { 8051c9263fSAatir Manzur return _data; 8151c9263fSAatir Manzur } 8251c9263fSAatir Manzur 83acb7c106SMatt Spinler /** 84acb7c106SMatt Spinler * @brief Get the section contents in JSON 85f67bafd0SHarisuddin Mohamed Isa * @param[in] creatorID - Creator Subsystem ID from Private Header 863fdcd4e8SHarisuddin Mohamed Isa * @param[in] plugins - Vector of strings of plugins found in filesystem 87acb7c106SMatt Spinler * @return The JSON as a string if a parser was found, 88acb7c106SMatt Spinler * otherwise std::nullopt. 89acb7c106SMatt Spinler */ 90*25291157SPatrick Williams std::optional<std::string> getJSON( 91*25291157SPatrick Williams uint8_t creatorID, 923fdcd4e8SHarisuddin Mohamed Isa const std::vector<std::string>& plugins) const override; 93acb7c106SMatt Spinler 94cbf3c4d4SMatt Spinler /** 95cbf3c4d4SMatt Spinler * @brief Shrink the section 96cbf3c4d4SMatt Spinler * 97cbf3c4d4SMatt Spinler * The new size must be between the current size and the minimum 98cbf3c4d4SMatt Spinler * size, which is 12 bytes. If it isn't a 4 byte aligned value 99cbf3c4d4SMatt Spinler * the code will do the aligning before the resize takes place. 100cbf3c4d4SMatt Spinler * 101cbf3c4d4SMatt Spinler * @param[in] newSize - The new size in bytes 102cbf3c4d4SMatt Spinler * 103cbf3c4d4SMatt Spinler * @return bool - true if successful, false else. 104cbf3c4d4SMatt Spinler */ 105cbf3c4d4SMatt Spinler bool shrink(size_t newSize) override; 106cbf3c4d4SMatt Spinler 10751c9263fSAatir Manzur private: 10851c9263fSAatir Manzur /** 10951c9263fSAatir Manzur * @brief Fills in the object from the stream data 11051c9263fSAatir Manzur * 11151c9263fSAatir Manzur * @param[in] stream - The stream to read from 11251c9263fSAatir Manzur */ 11351c9263fSAatir Manzur void unflatten(Stream& stream); 11451c9263fSAatir Manzur 11551c9263fSAatir Manzur /** 11651c9263fSAatir Manzur * @brief Validates the section contents 11751c9263fSAatir Manzur * 11851c9263fSAatir Manzur * Updates _valid (in Section) with the results. 11951c9263fSAatir Manzur */ 12051c9263fSAatir Manzur void validate() override; 12151c9263fSAatir Manzur 12251c9263fSAatir Manzur /** 12351c9263fSAatir Manzur * @brief The section data 12451c9263fSAatir Manzur */ 12551c9263fSAatir Manzur std::vector<uint8_t> _data; 12651c9263fSAatir Manzur }; 12751c9263fSAatir Manzur 12851c9263fSAatir Manzur } // namespace pels 12951c9263fSAatir Manzur } // namespace openpower 130