mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-25 08:17:32 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
617c0329df | |||
57354de831 | |||
c99af48e97 | |||
0741bd9e68 | |||
8d3d9c718d | |||
5ed9daae91 | |||
0e7262a77b |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -5,7 +5,7 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y clang-format
|
||||
|
@ -1,6 +1,12 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
HEAD
|
||||
----
|
||||
|
||||
* Improve error messages when using `char` or `char*` (issue #2043)
|
||||
* Make string support even more generic (PR #2084 by @d-a-v)
|
||||
|
||||
v6.21.5 (2024-01-10)
|
||||
-------
|
||||
|
||||
|
@ -154,15 +154,18 @@ TEST_CASE("ConverterNeedsWriteableRef") {
|
||||
}
|
||||
|
||||
namespace ArduinoJson {
|
||||
void convertToJson(char c, JsonVariant var) {
|
||||
char buf[] = {c, 0};
|
||||
var.set(buf);
|
||||
}
|
||||
template <>
|
||||
struct Converter<char> {
|
||||
static void toJson(char c, JsonVariant var) {
|
||||
char buf[] = {c, 0};
|
||||
var.set(buf);
|
||||
}
|
||||
|
||||
void convertFromJson(JsonVariantConst src, char& dst) {
|
||||
auto p = src.as<const char*>();
|
||||
dst = p ? p[0] : 0;
|
||||
}
|
||||
static char fromJson(JsonVariantConst src) {
|
||||
auto p = src.as<const char*>();
|
||||
return p ? p[0] : 0;
|
||||
}
|
||||
};
|
||||
} // namespace ArduinoJson
|
||||
|
||||
TEST_CASE("Convert char to string") { // issue #1922
|
||||
|
@ -13,7 +13,7 @@ static void check(const char* input, T expected) {
|
||||
uint8_t* f = reinterpret_cast<uint8_t*>(&actual);
|
||||
const uint8_t* d = reinterpret_cast<const uint8_t*>(input);
|
||||
doubleToFloat(d, f);
|
||||
fixEndianess(actual);
|
||||
fixEndianness(actual);
|
||||
CHECK(actual == expected);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ version: "6.21.5"
|
||||
description: >-
|
||||
A simple and efficient JSON library for embedded C++.
|
||||
ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more.
|
||||
It is the most popular Arduino library on GitHub ❤❤❤❤❤.
|
||||
It is the most popular Arduino library on GitHub ♥.
|
||||
Check out arduinojson.org for a comprehensive documentation.
|
||||
url: https://arduinojson.org/
|
||||
files:
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <ArduinoJson/Deserialization/deserialize.hpp>
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/MsgPack/endianess.hpp>
|
||||
#include <ArduinoJson/MsgPack/endianness.hpp>
|
||||
#include <ArduinoJson/MsgPack/ieee754.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
@ -258,7 +258,7 @@ class MsgPackDeserializer {
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
fixEndianess(value);
|
||||
fixEndianness(value);
|
||||
|
||||
return DeserializationError::Ok;
|
||||
}
|
||||
@ -287,7 +287,7 @@ class MsgPackDeserializer {
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
fixEndianess(value);
|
||||
fixEndianness(value);
|
||||
variant->setFloat(value);
|
||||
|
||||
return DeserializationError::Ok;
|
||||
@ -303,7 +303,7 @@ class MsgPackDeserializer {
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
fixEndianess(value);
|
||||
fixEndianness(value);
|
||||
variant->setFloat(value);
|
||||
|
||||
return DeserializationError::Ok;
|
||||
@ -322,7 +322,7 @@ class MsgPackDeserializer {
|
||||
return err;
|
||||
|
||||
doubleToFloat(i, o);
|
||||
fixEndianess(value);
|
||||
fixEndianness(value);
|
||||
variant->setFloat(value);
|
||||
|
||||
return DeserializationError::Ok;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/MsgPack/endianess.hpp>
|
||||
#include <ArduinoJson/MsgPack/endianness.hpp>
|
||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Serialization/CountingDecorator.hpp>
|
||||
@ -190,7 +190,7 @@ class MsgPackSerializer : public Visitor<size_t> {
|
||||
|
||||
template <typename T>
|
||||
void writeInteger(T value) {
|
||||
fixEndianess(value);
|
||||
fixEndianness(value);
|
||||
writeBytes(reinterpret_cast<uint8_t*>(&value), sizeof(value));
|
||||
}
|
||||
|
||||
|
@ -15,32 +15,32 @@ inline void swapBytes(uint8_t& a, uint8_t& b) {
|
||||
b = t;
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 8>) {
|
||||
inline void fixEndianness(uint8_t* p, integral_constant<size_t, 8>) {
|
||||
swapBytes(p[0], p[7]);
|
||||
swapBytes(p[1], p[6]);
|
||||
swapBytes(p[2], p[5]);
|
||||
swapBytes(p[3], p[4]);
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 4>) {
|
||||
inline void fixEndianness(uint8_t* p, integral_constant<size_t, 4>) {
|
||||
swapBytes(p[0], p[3]);
|
||||
swapBytes(p[1], p[2]);
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 2>) {
|
||||
inline void fixEndianness(uint8_t* p, integral_constant<size_t, 2>) {
|
||||
swapBytes(p[0], p[1]);
|
||||
}
|
||||
|
||||
inline void fixEndianess(uint8_t*, integral_constant<size_t, 1>) {}
|
||||
inline void fixEndianness(uint8_t*, integral_constant<size_t, 1>) {}
|
||||
|
||||
template <typename T>
|
||||
inline void fixEndianess(T& value) {
|
||||
fixEndianess(reinterpret_cast<uint8_t*>(&value),
|
||||
integral_constant<size_t, sizeof(T)>());
|
||||
inline void fixEndianness(T& value) {
|
||||
fixEndianness(reinterpret_cast<uint8_t*>(&value),
|
||||
integral_constant<size_t, sizeof(T)>());
|
||||
}
|
||||
#else
|
||||
template <typename T>
|
||||
inline void fixEndianess(T&) {}
|
||||
inline void fixEndianness(T&) {}
|
||||
#endif
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
@ -38,16 +38,15 @@ struct has_data<T,
|
||||
const char*>::value>::type>
|
||||
: true_type {};
|
||||
|
||||
// size_t length() const
|
||||
// unsigned int length() const
|
||||
// - String
|
||||
|
||||
template <class T, class = void>
|
||||
struct has_length : false_type {};
|
||||
|
||||
template <class T>
|
||||
struct has_length<
|
||||
T, typename enable_if<
|
||||
is_same<decltype(declval<const T>().length()), size_t>::value>::type>
|
||||
struct has_length<T, typename enable_if<is_unsigned<
|
||||
decltype(declval<const T>().length())>::value>::type>
|
||||
: true_type {};
|
||||
|
||||
// size_t size() const
|
||||
|
@ -20,6 +20,10 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
|
||||
template <typename T, typename Enable>
|
||||
struct Converter {
|
||||
static_assert(!detail::is_same<T, char>::value,
|
||||
"type 'char' is not supported, use 'signed char', 'unsigned "
|
||||
"char' or another integer type instead");
|
||||
|
||||
static void toJson(const T& src, JsonVariant dst) {
|
||||
// clang-format off
|
||||
convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/
|
||||
@ -27,6 +31,9 @@ struct Converter {
|
||||
}
|
||||
|
||||
static T fromJson(JsonVariantConst src) {
|
||||
static_assert(!detail::is_same<T, char*>::value,
|
||||
"type 'char*' is not supported, use 'const char*' instead");
|
||||
|
||||
// clang-format off
|
||||
T result; // Error here? See https://arduinojson.org/v6/non-default-constructible/
|
||||
convertFromJson(src, result); // Error here? See https://arduinojson.org/v6/unsupported-as/
|
||||
@ -35,6 +42,9 @@ struct Converter {
|
||||
}
|
||||
|
||||
static bool checkJson(JsonVariantConst src) {
|
||||
static_assert(!detail::is_same<T, char*>::value,
|
||||
"type 'char*' is not supported, use 'const char*' instead");
|
||||
|
||||
T dummy = T();
|
||||
// clang-format off
|
||||
return canConvertFromJson(src, dummy); // Error here? See https://arduinojson.org/v6/unsupported-is/
|
||||
|
@ -95,11 +95,9 @@ class VariantRefBase : public VariantTag {
|
||||
// Returns true if the value is of the specified type.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<!ConverterNeedsWriteableRef<T>::value &&
|
||||
!is_same<T, char*>::value &&
|
||||
!is_same<T, char>::value,
|
||||
bool>::type
|
||||
is() const {
|
||||
FORCE_INLINE
|
||||
typename enable_if<!ConverterNeedsWriteableRef<T>::value, bool>::type
|
||||
is() const {
|
||||
return Converter<T>::checkJson(getVariantConst());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user