2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "iot/mqtt-fast/types/Binary.h"
44#ifndef DOXYGEN_SHOULD_SKIP_THIS
57 this->length =
this->needed =
static_cast<std::vector<
char>::size_type>(length);
59 binary.resize(
static_cast<std::vector<
char>::size_type>(length),
'\0');
67 std::size_t consumed = 0;
98 ret = be16toh(*
reinterpret_cast<uint16_t*>(
binary.data() +
pointer));
112 ret = be32toh(*
reinterpret_cast<uint32_t*>(
binary.data() +
pointer));
126 ret = be64toh(*
reinterpret_cast<uint64_t*>(
binary.data() +
pointer));
138 uint32_t multiplier = 1;
142 const uint8_t byte = *
reinterpret_cast<uint8_t*>(
binary.data() +
pointer);
143 value += (byte & 0x7F) * multiplier;
145 if (multiplier > 0x80 * 0x80 * 0x80) {
195 std::list<uint8_t> uint8List;
199 uint8List.push_back(*
reinterpret_cast<uint8_t*>((
binary.data() +
pointer)));
209 binary.push_back(
static_cast<
char>(value));
211 length +=
sizeof(uint8_t);
215 binary.push_back(
static_cast<
char>(value >> 0x08 & 0xFF));
216 binary.push_back(
static_cast<
char>(value & 0xFF));
218 length +=
sizeof(uint16_t);
222 binary.push_back(
static_cast<
char>(value >> 0x18 & 0xFF));
223 binary.push_back(
static_cast<
char>(value >> 0x10 & 0xFF));
224 binary.push_back(
static_cast<
char>(value >> 0x08 & 0xFF));
225 binary.push_back(
static_cast<
char>(value & 0xFF));
227 length +=
sizeof(uint32_t);
231 binary.push_back(
static_cast<
char>(value >> 0x38 & 0xFF));
232 binary.push_back(
static_cast<
char>(value >> 0x30 & 0xFF));
233 binary.push_back(
static_cast<
char>(value >> 0x28 & 0xFF));
234 binary.push_back(
static_cast<
char>(value >> 0x20 & 0xFF));
235 binary.push_back(
static_cast<
char>(value >> 0x18 & 0xFF));
236 binary.push_back(
static_cast<
char>(value >> 0x10 & 0xFF));
237 binary.push_back(
static_cast<
char>(value >> 0x08 & 0xFF));
238 binary.push_back(
static_cast<
char>(value & 0xFF));
240 length +=
sizeof(uint64_t);
245 uint8_t encodedByte =
static_cast<uint8_t>(value % 0x80);
257 const uint16_t stringLen =
static_cast<uint16_t>(string.length());
264 binary.insert(
binary.end(), string.begin(), string.end());
266 length += string.length();
270 for (
const uint8_t value : values) {
std::vector< char >::size_type needed
std::vector< char >::size_type length
std::size_t construct() override
void putUint8ListRaw(const std::list< uint8_t > &values)
void putInt64(uint64_t value)
std::list< uint8_t > getUint8ListRaw()
std::string getStringRaw()
void putStringRaw(const std::string &string)
std::vector< char > binary
void putInt8(uint8_t value)
Binary(core::socket::SocketContext *socketContext=nullptr)
void putInt32(uint32_t value)
std::vector< char > & getValue()
void putString(const std::string &string)
std::vector< char >::size_type getLength() const
void setLength(std::vector< char >::size_type length)
void putIntV(uint32_t value)
void putInt16(uint16_t value)
std::vector< char >::size_type pointer
TypeBase(core::socket::SocketContext *socketContext)
std::size_t read(char *buf, std::size_t count)