1 // Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 2 // This Source Code Form is subject to the terms of the Mozilla Public 3 // License, v. 2.0. If a copy of the MPL was not distributed with this 4 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 #include "../include/constants.hpp" 7 #include "../include/option_impl.hpp" 8 #include "../../message/include/deserializer.hpp" 9 #include "../../message/include/serializer.hpp" 10 11 namespace vsomeip_v3 { 12 namespace sd { 13 option_impl()14option_impl::option_impl() : 15 length_(0), 16 type_(option_type_e::UNKNOWN) { 17 } 18 ~option_impl()19option_impl::~option_impl() { 20 } 21 operator ==(const option_impl & _other) const22bool option_impl::operator ==(const option_impl &_other) const { 23 return (type_ == _other.type_ && length_ == _other.length_); 24 } 25 26 bool equals(const std::shared_ptr<option_impl> & _other) const27option_impl::equals(const std::shared_ptr<option_impl> &_other) const { 28 return (this->operator ==(*(_other.get()))); 29 } 30 get_length() const31uint16_t option_impl::get_length() const { 32 return length_; 33 } 34 get_type() const35option_type_e option_impl::get_type() const { 36 return type_; 37 } 38 serialize(vsomeip_v3::serializer * _to) const39bool option_impl::serialize(vsomeip_v3::serializer *_to) const { 40 return (0 != _to && _to->serialize(length_) 41 && _to->serialize(static_cast<uint8_t>(type_)) 42 && _to->serialize(protocol::reserved_byte)); 43 } 44 deserialize(vsomeip_v3::deserializer * _from)45bool option_impl::deserialize(vsomeip_v3::deserializer *_from) { 46 uint8_t its_type, reserved; 47 bool l_result = (0 != _from && _from->deserialize(length_) 48 && _from->deserialize(its_type) && _from->deserialize(reserved)); 49 50 if (l_result) { 51 switch(static_cast<option_type_e>(its_type)) { 52 case option_type_e::CONFIGURATION: 53 case option_type_e::LOAD_BALANCING: 54 case option_type_e::PROTECTION: 55 case option_type_e::IP4_ENDPOINT: 56 case option_type_e::IP6_ENDPOINT: 57 case option_type_e::IP4_MULTICAST: 58 case option_type_e::IP6_MULTICAST: 59 case option_type_e::SELECTIVE: 60 type_ = static_cast<option_type_e>(its_type); 61 break; 62 default: 63 type_ = option_type_e::UNKNOWN; 64 // No valid option type --> ignore the remaining parts of the message! 65 _from->set_remaining(0); 66 } 67 } 68 69 return l_result; 70 } 71 72 } // namespace sd 73 } // namespace vsomeip_v3 74