blob: 528b46d98578aa117495d06e4092dda614beee28 [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinler14d671f2019-09-25 13:11:22 -050016#include "generic.hpp"
17
18#include <phosphor-logging/log.hpp>
19
20namespace openpower
21{
22namespace pels
23{
24
25using namespace phosphor::logging;
26
27void Generic::unflatten(Stream& stream)
28{
29 stream >> _header;
30
31 if (_header.size <= SectionHeader::flattenedSize())
32 {
33 throw std::out_of_range(
34 "Generic::unflatten: SectionHeader::size field too small");
35 }
36
37 size_t dataLength = _header.size - SectionHeader::flattenedSize();
38 _data.resize(dataLength);
39
40 stream >> _data;
41}
42
Matt Spinler06885452019-11-06 10:35:42 -060043void Generic::flatten(Stream& stream) const
Matt Spinler14d671f2019-09-25 13:11:22 -050044{
45 stream << _header << _data;
46}
47
48Generic::Generic(Stream& pel)
49{
50 try
51 {
52 unflatten(pel);
53 validate();
54 }
55 catch (const std::exception& e)
56 {
57 log<level::ERR>("Cannot unflatten generic section",
58 entry("ERROR=%s", e.what()));
59 _valid = false;
60 }
61}
62
63void Generic::validate()
64{
65 // Nothing to validate
66 _valid = true;
67}
68
69} // namespace pels
70} // namespace openpower