• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/protection_option_impl.hpp"
7 #include "../../message/include/deserializer.hpp"
8 #include "../../message/include/serializer.hpp"
9 
10 namespace vsomeip_v3 {
11 namespace sd {
12 
protection_option_impl()13 protection_option_impl::protection_option_impl() {
14     length_ = 1 + 4 + 4;
15     type_ = option_type_e::PROTECTION;
16     counter_ = 0;
17     crc_ = 0;
18 }
19 
~protection_option_impl()20 protection_option_impl::~protection_option_impl() {
21 }
22 
23 bool
operator ==(const option_impl & _other) const24 protection_option_impl::operator ==(const option_impl &_other) const {
25     bool is_equal(option_impl::operator ==(_other));
26 
27     if (is_equal) {
28         const protection_option_impl &its_other
29             = dynamic_cast<const protection_option_impl &>(_other);
30         is_equal = (counter_ == its_other.counter_
31                 && crc_ == its_other.crc_);
32     }
33 
34     return is_equal;
35 }
36 
get_alive_counter() const37 alive_counter_t protection_option_impl::get_alive_counter() const {
38     return counter_;
39 }
40 
set_alive_counter(alive_counter_t _counter)41 void protection_option_impl::set_alive_counter(alive_counter_t _counter) {
42     counter_ = _counter;
43 }
44 
get_crc() const45 crc_t protection_option_impl::get_crc() const {
46     return crc_;
47 }
48 
set_crc(crc_t _crc)49 void protection_option_impl::set_crc(crc_t _crc) {
50     crc_ = _crc;
51 }
52 
serialize(vsomeip_v3::serializer * _to) const53 bool protection_option_impl::serialize(vsomeip_v3::serializer *_to) const {
54     bool is_successful = option_impl::serialize(_to);
55     is_successful = is_successful
56             && _to->serialize(static_cast<uint32_t>(counter_));
57     is_successful = is_successful
58             && _to->serialize(static_cast<uint32_t>(crc_));
59     return is_successful;
60 }
61 
deserialize(vsomeip_v3::deserializer * _from)62 bool protection_option_impl::deserialize(vsomeip_v3::deserializer *_from) {
63     bool is_successful = option_impl::deserialize(_from);
64 
65     uint32_t its_alive_counter = 0;
66     is_successful = is_successful && _from->deserialize(its_alive_counter);
67     counter_ = static_cast<alive_counter_t>(its_alive_counter);
68 
69     uint32_t its_crc = 0;
70     is_successful = is_successful && _from->deserialize(its_crc);
71     crc_ = static_cast<crc_t>(its_crc);
72 
73     return is_successful;
74 }
75 
76 } // namespace sd
77 } // namespace vsomeip_v3
78