SNode.C
Loading...
Searching...
No Matches
TypeBase.hpp
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/MqttContext.h"
21#include "iot/mqtt/types/TypeBase.h"
22
23#ifndef DOXYGEN_SHOULD_SKIP_THIS
24
25#endif // DOXYGEN_SHOULD_SKIP_THIS
26
27namespace iot::mqtt::types {
28
29 template <typename ValueType>
30 TypeBase<ValueType>::TypeBase(std::size_t size) {
31 value.resize(size);
32 length = size;
33 needed = size;
34 }
35
36 template <typename ValueType>
37 std::size_t TypeBase<ValueType>::deserialize(iot::mqtt::MqttContext* mqttContext) {
38 std::size_t consumed = 0;
39
40 consumed = mqttContext->recv(value.data() + length - needed, needed);
41 needed -= consumed;
43
44 return consumed;
45 }
46
47 template <typename ValueType>
48 void TypeBase<ValueType>::setSize(std::size_t size) {
49 value.resize(size);
50
51 length = size;
52 needed = size;
53 }
55 template <typename ValueTypeT>
56 std::size_t TypeBase<ValueTypeT>::size() {
57 return length;
58 }
59
60 template <typename ValueType>
61 std::vector<char> iot::mqtt::types::TypeBase<ValueType>::serialize() const {
62 return value;
63 }
64
65 template <typename ValueType>
66 bool TypeBase<ValueType>::isComplete() const {
67 return complete;
68 }
69
70 template <typename ValueType>
71 void TypeBase<ValueType>::reset(std::size_t size) {
72 value.resize(size);
73
74 length = size;
75 needed = size;
76
77 complete = false;
78
79 state = 0;
80 }
81
82} // namespace iot::mqtt::types
BinaryData(const BinaryData &)=default
bool operator==(const std::vector< char > &rhsValue) const
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext) override
BinaryData & operator=(BinaryData &&) noexcept=default
void reset(std::size_t size=0) override
BinaryData & operator=(const std::vector< char > &newValue)
bool operator!=(const std::vector< char > &rhsValue) const
BinaryData(BinaryData &&) noexcept=default
std::vector< char > serialize() const override
BinaryData & operator=(const BinaryData &)=default
void setSize(std::size_t size)
Definition TypeBase.hpp:48
virtual std::vector< char > serialize() const
Definition TypeBase.hpp:61
virtual std::size_t deserialize(iot::mqtt::MqttContext *mqttContext)
Definition TypeBase.hpp:37
TypeBase(std::size_t size=sizeof(ValueType))
Definition TypeBase.hpp:30
virtual void reset(std::size_t size=sizeof(ValueType))
Definition TypeBase.hpp:71