text: #include "private_header.hpp"
  
  #include <phosphor-logging/log.hpp>
  
  namespace openpower
  {
  namespace pels
  {
  
  using namespace phosphor::logging;
  
  PrivateHeader::PrivateHeader(Stream& pel)
  {
      try
      {
          unflatten(pel);
          validate();
      }
      catch (const std::exception& e)
      {
          log<level::ERR>("Cannot unflatten private header",
                          entry("ERROR=%s", e.what()));
          _valid = false;
      }
  }
  
  void PrivateHeader::validate()
  {
      bool failed = false;
  
      if (header().id != privateHeaderSectionID)
      {
          log<level::ERR>("Invalid private header section ID",
                          entry("ID=0x%X", header().id));
          failed = true;
      }
  
      if (header().version != privateHeaderVersion)
      {
          log<level::ERR>("Invalid private header version",
                          entry("VERSION=0x%X", header().version));
          failed = true;
      }
  
      if (_sectionCount < minSectionCount)
      {
          log<level::ERR>("Invalid section count in private header",
                          entry("SECTION_COUNT=0x%X", _sectionCount));
          failed = true;
      }
  
      _valid = (failed) ? false : true;
  }
  
  void PrivateHeader::unflatten(Stream& stream)
  {
      stream >> _header >> _createTimestamp >> _commitTimestamp >> _creatorID >>
          _logType >> _reservedByte >> _sectionCount >> _obmcLogID >>
          _creatorVersion >> _plid >> _id;
  }
  
  void PrivateHeader::flatten(Stream& stream)
  {
      stream << _header << _createTimestamp << _commitTimestamp << _creatorID
             << _logType << _reservedByte << _sectionCount << _obmcLogID
             << _creatorVersion << _plid << _id;
  }
  
  Stream& operator>>(Stream& s, CreatorVersion& cv)
  {
      for (size_t i = 0; i < sizeof(CreatorVersion); i++)
      {
          s >> cv.version[i];
      }
      return s;
  }
  
  Stream& operator<<(Stream& s, CreatorVersion& cv)
  {
      for (size_t i = 0; i < sizeof(CreatorVersion); i++)
      {
          s << cv.version[i];
      }
      return s;
  }
  
  } // namespace pels
  } // namespace openpower
  