1711d51d8SMatt Spinler /**
2711d51d8SMatt Spinler  * Copyright © 2019 IBM Corporation
3711d51d8SMatt Spinler  *
4711d51d8SMatt Spinler  * Licensed under the Apache License, Version 2.0 (the "License");
5711d51d8SMatt Spinler  * you may not use this file except in compliance with the License.
6711d51d8SMatt Spinler  * You may obtain a copy of the License at
7711d51d8SMatt Spinler  *
8711d51d8SMatt Spinler  *     http://www.apache.org/licenses/LICENSE-2.0
9711d51d8SMatt Spinler  *
10711d51d8SMatt Spinler  * Unless required by applicable law or agreed to in writing, software
11711d51d8SMatt Spinler  * distributed under the License is distributed on an "AS IS" BASIS,
12711d51d8SMatt Spinler  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13711d51d8SMatt Spinler  * See the License for the specific language governing permissions and
14711d51d8SMatt Spinler  * limitations under the License.
15711d51d8SMatt Spinler  */
165b3a11dbSMatt Spinler #include "pce_identity.hpp"
175b3a11dbSMatt Spinler 
185b3a11dbSMatt Spinler namespace openpower
195b3a11dbSMatt Spinler {
205b3a11dbSMatt Spinler namespace pels
215b3a11dbSMatt Spinler {
225b3a11dbSMatt Spinler namespace src
235b3a11dbSMatt Spinler {
245b3a11dbSMatt Spinler 
PCEIdentity(Stream & pel)255b3a11dbSMatt Spinler PCEIdentity::PCEIdentity(Stream& pel)
265b3a11dbSMatt Spinler {
275b3a11dbSMatt Spinler     pel >> _type >> _size >> _flags >> _mtms;
285b3a11dbSMatt Spinler 
295b3a11dbSMatt Spinler     // Whatever is left is the enclosure name.
305b3a11dbSMatt Spinler     if (_size < (4 + _mtms.flattenedSize()))
315b3a11dbSMatt Spinler     {
325b3a11dbSMatt Spinler         throw std::runtime_error("PCE identity structure size field too small");
335b3a11dbSMatt Spinler     }
345b3a11dbSMatt Spinler 
355b3a11dbSMatt Spinler     size_t pceNameSize = _size - (4 + _mtms.flattenedSize());
365b3a11dbSMatt Spinler 
375b3a11dbSMatt Spinler     _pceName.resize(pceNameSize);
385b3a11dbSMatt Spinler     pel >> _pceName;
395b3a11dbSMatt Spinler }
405b3a11dbSMatt Spinler 
flatten(Stream & pel) const41*724d0d8cSMatt Spinler void PCEIdentity::flatten(Stream& pel) const
425b3a11dbSMatt Spinler {
435b3a11dbSMatt Spinler     pel << _type << _size << _flags << _mtms << _pceName;
445b3a11dbSMatt Spinler }
455b3a11dbSMatt Spinler 
465b3a11dbSMatt Spinler } // namespace src
475b3a11dbSMatt Spinler } // namespace pels
485b3a11dbSMatt Spinler } // namespace openpower
49