2016-01-07 22:35:12 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2016
|
2014-10-23 23:39:22 +02:00
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
2016-01-07 22:35:12 +01:00
|
|
|
// If you like this project, please add a star!
|
2014-10-16 00:11:23 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-05-06 08:44:31 +02:00
|
|
|
#include "../Print.hpp"
|
2014-10-16 00:11:23 +02:00
|
|
|
|
2014-10-23 19:54:00 +02:00
|
|
|
namespace ArduinoJson {
|
|
|
|
namespace Internals {
|
2014-11-06 14:48:14 +01:00
|
|
|
|
|
|
|
// A Print implementation that allows to write in a char[]
|
2015-08-10 17:22:22 +02:00
|
|
|
class StaticStringBuilder : public Print {
|
2014-10-23 23:13:13 +02:00
|
|
|
public:
|
2015-10-30 23:03:16 +01:00
|
|
|
StaticStringBuilder(char *buf, size_t size)
|
2014-10-23 19:54:00 +02:00
|
|
|
: buffer(buf), capacity(size - 1), length(0) {
|
2014-11-03 17:03:55 +01:00
|
|
|
buffer[0] = '\0';
|
2014-10-23 19:54:00 +02:00
|
|
|
}
|
2014-10-16 00:11:23 +02:00
|
|
|
|
2016-06-22 21:41:19 +02:00
|
|
|
virtual size_t write(uint8_t c) {
|
|
|
|
if (length >= capacity) return 0;
|
|
|
|
|
|
|
|
buffer[length++] = c;
|
|
|
|
buffer[length] = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|
2014-10-16 00:11:23 +02:00
|
|
|
|
2014-10-23 23:13:13 +02:00
|
|
|
private:
|
2014-10-23 19:54:00 +02:00
|
|
|
char *buffer;
|
2015-10-30 23:03:16 +01:00
|
|
|
size_t capacity;
|
|
|
|
size_t length;
|
2014-10-23 19:54:00 +02:00
|
|
|
};
|
|
|
|
}
|
2014-10-23 23:45:36 +02:00
|
|
|
}
|