SNode.C
Loading...
Searching...
No Matches
BinaryData.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "iot/mqtt/types/BinaryData.h"
21
22#include "iot/mqtt/types/TypeBase.hpp"
23
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
25
26#include <cstdint>
27
28#endif // DOXYGEN_SHOULD_SKIP_THIS
29
30namespace iot::mqtt::types {
31
33 : TypeBase(0) {
34 }
35
38
39 std::size_t BinaryData::deserialize(MqttContext* mqttContext) {
40 std::size_t consumed = 0;
41
42 switch (state) {
43 case 0:
44 consumed = valueLength.deserialize(mqttContext);
45 if (!valueLength.isComplete()) {
46 break;
47 }
48
49 setSize(valueLength);
50 state++;
51 [[fallthrough]];
52 case 1:
53 consumed += TypeBase::deserialize(mqttContext);
54 break;
55 }
56
57 return consumed;
58 }
59
60 std::vector<char> BinaryData::serialize() const {
61 std::vector<char> returnVector = valueLength.serialize();
62 returnVector.insert(returnVector.end(), value.begin(), value.end());
63
64 return returnVector;
65 }
66
67 BinaryData& BinaryData::operator=(const std::vector<char>& newValue) {
68 value = newValue;
69 valueLength = static_cast<uint16_t>(value.size());
70
71 return *this;
72 }
73
74 BinaryData::operator std::vector<char>() const {
75 return value;
76 }
77
78 bool BinaryData::operator==(const std::vector<char>& rhsValue) const {
79 return static_cast<std::vector<char>>(*this) == rhsValue;
80 }
81
82 bool BinaryData::operator!=(const std::vector<char>& rhsValue) const {
83 return static_cast<std::vector<char>>(*this) != rhsValue;
84 }
85
86 void BinaryData::reset([[maybe_unused]] std::size_t size) {
87 valueLength.reset();
88 TypeBase::reset(0);
89
90 state = 0;
91 }
92
93 template class TypeBase<std::vector<char>>;
94
95} // namespace iot::mqtt::types
bool operator==(const std::vector< char > &rhsValue) const
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext) override
void reset(std::size_t size=0) override
BinaryData & operator=(const std::vector< char > &newValue)
bool operator!=(const std::vector< char > &rhsValue) const
std::vector< char > serialize() const override