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
30
namespace
iot::mqtt::
types
{
31
32
BinaryData
::
BinaryData
()
33
:
TypeBase
(0) {
34
}
35
36
BinaryData
::~
BinaryData
() {
37
}
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
iot::mqtt::MqttContext
Definition
MqttContext.h:39
iot::mqtt::types::BinaryData
Definition
BinaryData.h:39
iot::mqtt::types::BinaryData::operator==
bool operator==(const std::vector< char > &rhsValue) const
Definition
BinaryData.cpp:78
iot::mqtt::types::BinaryData::deserialize
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext) override
Definition
BinaryData.cpp:39
iot::mqtt::types::BinaryData::~BinaryData
~BinaryData() override
Definition
BinaryData.cpp:36
iot::mqtt::types::BinaryData::BinaryData
BinaryData()
Definition
BinaryData.cpp:32
iot::mqtt::types::BinaryData::reset
void reset(std::size_t size=0) override
Definition
BinaryData.cpp:86
iot::mqtt::types::BinaryData::operator=
BinaryData & operator=(const std::vector< char > &newValue)
Definition
BinaryData.cpp:67
iot::mqtt::types::BinaryData::operator!=
bool operator!=(const std::vector< char > &rhsValue) const
Definition
BinaryData.cpp:82
iot::mqtt::types::BinaryData::serialize
std::vector< char > serialize() const override
Definition
BinaryData.cpp:60
iot::mqtt::types
Definition
String.h:33
iot
mqtt
types
BinaryData.cpp
Generated on Mon Feb 10 2025 20:21:20 for SNode.C by
1.11.0