MCPcopy Create free account
hub / github.com/COVESA/vsomeip / deserialize

Method deserialize

implementation/protocol/src/assign_client_command.cpp:57–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57void assign_client_command::deserialize(const std::vector<byte_t>& _buffer, error_e& _error) {
58
59 if (_buffer.size() < COMMAND_HEADER_SIZE) {
60 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
61 return;
62 }
63
64 command::deserialize(_buffer, _error);
65 if (_error != error_e::ERROR_OK)
66 return;
67
68 size_t read_position(COMMAND_POSITION_PAYLOAD);
69 size_t remaining(_buffer.size() - COMMAND_HEADER_SIZE);
70
71 // deserialize name length and name
72 if (remaining < sizeof(uint32_t)) {
73 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
74 return;
75 }
76
77 uint32_t name_length = 0;
78 std::memcpy(&name_length, &_buffer[read_position], sizeof(uint32_t));
79 read_position += sizeof(uint32_t);
80 remaining -= sizeof(uint32_t);
81
82 if (remaining < name_length) {
83 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
84 return;
85 }
86
87 if (name_length > 0) {
88 name_.assign(&_buffer[read_position], &_buffer[read_position + name_length]);
89 read_position += name_length;
90 remaining -= name_length;
91 }
92
93 if (remaining < sizeof(uint8_t)) {
94 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
95 return;
96 }
97
98 uint8_t has_address = 0;
99 std::memcpy(&has_address, &_buffer[read_position], sizeof(uint8_t));
100 read_position += sizeof(uint8_t);
101 remaining -= sizeof(uint8_t);
102
103 if (has_address) {
104 if (remaining < sizeof(boost::asio::ip::address_v4::bytes_type) + sizeof(port_t)) {
105 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
106 return;
107 }
108 boost::asio::ip::address_v4::bytes_type its_array;
109 std::memcpy(&its_array, &_buffer[read_position], its_array.size());
110 address_ = boost::asio::ip::address_v4(its_array);
111 read_position += its_array.size();
112 std::memcpy(&port_, &_buffer[read_position], sizeof(port_t));
113 }
114}

Callers

nothing calls this directly

Calls 3

deserializeFunction · 0.85
sizeMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected