Line | |
---|
1 | // Copyright Benoit Blanchon 2014-2016
|
---|
2 | // MIT License
|
---|
3 | //
|
---|
4 | // Arduino JSON library
|
---|
5 | // https://github.com/bblanchon/ArduinoJson
|
---|
6 | // If you like this project, please add a star!
|
---|
7 |
|
---|
8 | #pragma once
|
---|
9 |
|
---|
10 | #include "JsonBuffer.hpp"
|
---|
11 |
|
---|
12 | namespace ArduinoJson {
|
---|
13 |
|
---|
14 | // Implements a JsonBuffer with fixed memory allocation.
|
---|
15 | // The template paramenter CAPACITY specifies the capacity of the buffer in
|
---|
16 | // bytes.
|
---|
17 | template <size_t CAPACITY>
|
---|
18 | class StaticJsonBuffer : public JsonBuffer {
|
---|
19 | public:
|
---|
20 | explicit StaticJsonBuffer() : _size(0) {}
|
---|
21 |
|
---|
22 | size_t capacity() const { return CAPACITY; }
|
---|
23 | size_t size() const { return _size; }
|
---|
24 |
|
---|
25 | virtual void* alloc(size_t bytes) {
|
---|
26 | if (_size + bytes > CAPACITY) return NULL;
|
---|
27 | void* p = &_buffer[_size];
|
---|
28 | _size += round_size_up(bytes);
|
---|
29 | return p;
|
---|
30 | }
|
---|
31 |
|
---|
32 | private:
|
---|
33 | uint8_t _buffer[CAPACITY];
|
---|
34 | size_t _size;
|
---|
35 | };
|
---|
36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.