SNode.C
Loading...
Searching...
No Matches
Int_V.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, 2025
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-fast/types/Int_V.h"
21
22
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
23
24
#
endif
// DOXYGEN_SHOULD_SKIP_THIS
25
26
namespace
iot::
mqtt_fast
::
types
{
27
28
Int_V
::
Int_V
(core::socket::
SocketContext
* socketContext)
29
: iot::
mqtt_fast
::
types
::
TypeBase
(
socketContext
)
{
30
}
31
32
std::size_t
Int_V
::
construct
() {
33
std::size_t consumed = 0;
34
std::size_t ret = 0;
35
36
do
{
37
char
byte = 0;
38
ret =
read
(
&byte
,
1
)
;
39
40
if
(ret > 0) {
41
value
+=
static_cast
<uint32_t>((byte & 0x7F) *
multiplier
);
42
if
(
multiplier
> 0x80 * 0x80 * 0x80) {
43
error
=
true
;
44
}
else
{
45
multiplier
*= 0x80;
46
completed
= (byte & 0x80) == 0;
47
}
48
consumed += ret;
49
}
50
}
while
(ret > 0 && !
completed
&& !
error
);
51
52
return
consumed;
53
}
54
55
uint32_t
Int_V
::
getValue
()
const
{
56
return
value
;
57
}
58
59
void
Int_V
::
reset
() {
60
multiplier
= 1;
61
value
= 0;
62
63
iot
::
mqtt_fast
::
types
::
TypeBase
::
reset
(
)
;
64
}
65
66
}
// namespace iot::mqtt_fast::types
core::socket::SocketContext
Definition
SocketContext.h:36
iot::mqtt_fast::types::Int_V
Definition
Int_V.h:38
iot::mqtt_fast::types::Int_V::value
std::uint32_t value
Definition
Int_V.h:50
iot::mqtt_fast::types::Int_V::getValue
uint32_t getValue() const
Definition
Int_V.cpp:55
iot::mqtt_fast::types::Int_V::reset
void reset() override
Definition
Int_V.cpp:59
iot::mqtt_fast::types::Int_V::construct
std::size_t construct() override
Definition
Int_V.cpp:32
iot::mqtt_fast::types::Int_V::multiplier
std::size_t multiplier
Definition
Int_V.h:49
iot::mqtt_fast::types::Int_V::Int_V
Int_V(core::socket::SocketContext *socketContext=nullptr)
Definition
Int_V.cpp:28
iot::mqtt_fast::types::TypeBase
Definition
TypeBase.h:35
iot::mqtt_fast::types::TypeBase::TypeBase
TypeBase(core::socket::SocketContext *socketContext)
Definition
TypeBase.cpp:30
iot::mqtt_fast::types::TypeBase::error
bool error
Definition
TypeBase.h:59
iot::mqtt_fast::types::TypeBase::reset
virtual void reset()
Definition
TypeBase.cpp:50
iot::mqtt_fast::types::TypeBase::completed
bool completed
Definition
TypeBase.h:58
iot::mqtt_fast::types::TypeBase::read
std::size_t read(char *buf, std::size_t count)
Definition
TypeBase.cpp:42
iot::mqtt_fast::types
Definition
Binary.h:39
iot
Definition
ControlPacket.cpp:30
iot
mqtt-fast
types
Int_V.cpp
Generated on Mon Feb 10 2025 20:21:05 for SNode.C by
1.11.0