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

Method deserialize

implementation/protocol/src/config_command.cpp:43–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void config_command::deserialize(const std::vector<byte_t>& _buffer, error_e& _error) {
44 if (_buffer.size() < COMMAND_HEADER_SIZE) {
45 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
46 return;
47 }
48 command::deserialize(_buffer, _error);
49 if (_error != error_e::ERROR_OK) {
50 return;
51 }
52 std::size_t remaining = size_;
53 if (_buffer.size() < COMMAND_HEADER_SIZE + remaining) {
54 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
55 return;
56 }
57 size_t read_position(COMMAND_POSITION_PAYLOAD);
58 std::function<std::string(bool&)> read = [&_buffer, &read_position, &remaining](bool& failed) {
59 if (remaining < sizeof(std::uint32_t)) {
60 failed = true;
61 return std::string("");
62 }
63 size_t size = 0;
64 std::memcpy(&size, &_buffer[read_position], sizeof(std::uint32_t));
65 remaining -= sizeof(std::uint32_t);
66 read_position += sizeof(std::uint32_t);
67
68 if (remaining < size || read_position + size > _buffer.size()) {
69 failed = true;
70 return std::string("");
71 }
72 std::string value;
73 if (size > 0) {
74 value.assign(_buffer.begin() + static_cast<std::ptrdiff_t>(read_position),
75 _buffer.begin() + static_cast<std::ptrdiff_t>(read_position + size));
76 }
77 remaining -= size;
78 read_position += size;
79 return value;
80 };
81 while (remaining > 0) {
82 bool failed = false;
83 std::string key = read(failed);
84 if (failed) {
85 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
86 return;
87 }
88 std::string value = read(failed);
89 if (failed) {
90 _error = error_e::ERROR_NOT_ENOUGH_BYTES;
91 return;
92 }
93 configs_[key] = value;
94 }
95 _error = error_e::ERROR_OK;
96}
97
98void config_command::insert(const std::string& _key, const std::string&& _value) {
99 configs_.insert_or_assign(_key, std::move(_value));

Callers

nothing calls this directly

Calls 4

deserializeFunction · 0.85
beginMethod · 0.80
sizeMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected