forked from bblanchon/ArduinoJson
Now use uint8_t to store decimal count
This commit is contained in:
@ -28,7 +28,7 @@ class JsonWriter {
|
|||||||
void writeString(const char *value);
|
void writeString(const char *value);
|
||||||
void writeInteger(long value);
|
void writeInteger(long value);
|
||||||
void writeBoolean(bool value);
|
void writeBoolean(bool value);
|
||||||
void writeDouble(double value, int decimals);
|
void writeDouble(double value, uint8_t decimals);
|
||||||
|
|
||||||
void writeColon() { _length += _sink->write(':'); }
|
void writeColon() { _length += _sink->write(':'); }
|
||||||
void writeComma() { _length += _sink->write(','); }
|
void writeComma() { _length += _sink->write(','); }
|
||||||
|
@ -41,7 +41,7 @@ class JsonArray : public JsonPrintable<JsonArray>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
value_type &add();
|
value_type &add();
|
||||||
void add(double value, int decimals) { add().set(value, decimals); }
|
void add(double value, uint8_t decimals) { add().set(value, decimals); }
|
||||||
void add(JsonArray &nestedArray) { add().set(nestedArray); }
|
void add(JsonArray &nestedArray) { add().set(nestedArray); }
|
||||||
void add(JsonObject &nestedObject) { add().set(nestedObject); }
|
void add(JsonObject &nestedObject) { add().set(nestedObject); }
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h> // for uint8_t
|
||||||
|
|
||||||
#include "Internals/JsonValueContent.hpp"
|
#include "Internals/JsonValueContent.hpp"
|
||||||
#include "Internals/JsonValueType.hpp"
|
#include "Internals/JsonValueType.hpp"
|
||||||
@ -25,7 +26,7 @@ class JsonValue {
|
|||||||
JsonValue() : _type(Internals::JSON_UNDEFINED) {}
|
JsonValue() : _type(Internals::JSON_UNDEFINED) {}
|
||||||
|
|
||||||
void set(bool value);
|
void set(bool value);
|
||||||
void set(double value, int decimals = 2);
|
void set(double value, uint8_t decimals = 2);
|
||||||
void set(signed char value) { set(static_cast<long>(value)); }
|
void set(signed char value) { set(static_cast<long>(value)); }
|
||||||
void set(signed int value) { set(static_cast<long>(value)); }
|
void set(signed int value) { set(static_cast<long>(value)); }
|
||||||
void set(signed long value);
|
void set(signed long value);
|
||||||
|
@ -118,7 +118,7 @@ void JsonParser::parseNumberTo(JsonValue &destination) {
|
|||||||
if (*endOfLong == '.') {
|
if (*endOfLong == '.') {
|
||||||
// stopped on a decimal separator
|
// stopped on a decimal separator
|
||||||
double doubleValue = strtod(_ptr, &_ptr);
|
double doubleValue = strtod(_ptr, &_ptr);
|
||||||
int decimals = _ptr - endOfLong - 1;
|
uint8_t decimals = _ptr - endOfLong - 1;
|
||||||
destination.set(doubleValue, decimals);
|
destination.set(doubleValue, decimals);
|
||||||
} else {
|
} else {
|
||||||
_ptr = endOfLong;
|
_ptr = endOfLong;
|
||||||
|
@ -19,6 +19,6 @@ void JsonWriter::writeBoolean(bool value) {
|
|||||||
_length += _sink->print(value ? "true" : "false");
|
_length += _sink->print(value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonWriter::writeDouble(double value, int decimals) {
|
void JsonWriter::writeDouble(double value, uint8_t decimals) {
|
||||||
_length += _sink->print(value, decimals);
|
_length += _sink->print(value, decimals);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ void JsonValue::set(const char *value) {
|
|||||||
_content.asString = value;
|
_content.asString = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonValue::set(double value, int decimals) {
|
void JsonValue::set(double value, uint8_t decimals) {
|
||||||
if (_type == JSON_INVALID) return;
|
if (_type == JSON_INVALID) return;
|
||||||
_type = static_cast<JsonValueType>(JSON_DOUBLE_0_DECIMALS + decimals);
|
_type = static_cast<JsonValueType>(JSON_DOUBLE_0_DECIMALS + decimals);
|
||||||
_content.asDouble = value;
|
_content.asDouble = value;
|
||||||
|
Reference in New Issue
Block a user