Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
src/ArduinoJson/Serialization/Writers/StaticStringWriter.hpp
- Committer:
- khaiminhvn
- Date:
- 2021-03-19
- Revision:
- 0:18ba3960b5dd
File content as of revision 0:18ba3960b5dd:
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
namespace ARDUINOJSON_NAMESPACE {
// A Print implementation that allows to write in a char[]
class StaticStringWriter {
public:
StaticStringWriter(char *buf, size_t size) : end(buf + size - 1), p(buf) {
*p = '\0';
}
size_t write(uint8_t c) {
if (p >= end)
return 0;
*p++ = static_cast<char>(c);
*p = '\0';
return 1;
}
size_t write(const uint8_t *s, size_t n) {
char *begin = p;
while (p < end && n > 0) {
*p++ = static_cast<char>(*s++);
n--;
}
*p = '\0';
return size_t(p - begin);
}
private:
char *end;
char *p;
};
} // namespace ARDUINOJSON_NAMESPACE