forked from Brill-Power/thingsetplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuffer.hpp
More file actions
43 lines (36 loc) · 817 Bytes
/
Buffer.hpp
File metadata and controls
43 lines (36 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Copyright (c) 2025 Brill Power.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <thingset++/ThingSet.hpp>
template <size_t Capacity>
class Buffer : public ThingSet::ThingSetDecodable, public ThingSet::ThingSetEncodable
{
private:
std::array<uint8_t, Capacity> _buffer;
size_t _size;
public:
Buffer() : _buffer(), _size(0)
{}
std::array<uint8_t, Capacity> &buffer()
{
return _buffer;
}
size_t &size()
{
return _size;
}
const size_t &size() const
{
return _size;
}
bool decode(ThingSet::ThingSetDecoder &decoder) override
{
return decoder.decodeBytes(_buffer, _size);
}
bool encode(ThingSet::ThingSetEncoder &encoder) const override
{
return encoder.encodeBytes(_buffer, _size);
}
};