mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Replace serializeJson()'s template parameter with JsonVariantConst
				
					
				
			This commit is contained in:
		| @@ -116,18 +116,17 @@ class JsonSerializer : public Visitor<size_t> { | |||||||
|   TextFormatter<TWriter> _formatter; |   TextFormatter<TWriter> _formatter; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| template <typename TSource, typename TDestination> | template <typename TDestination> | ||||||
| size_t serializeJson(const TSource &source, TDestination &destination) { | size_t serializeJson(VariantConstRef source, TDestination &destination) { | ||||||
|   return serialize<JsonSerializer>(source, destination); |   return serialize<JsonSerializer>(source, destination); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename TSource> | inline size_t serializeJson(VariantConstRef source, void *buffer, | ||||||
| size_t serializeJson(const TSource &source, void *buffer, size_t bufferSize) { |                             size_t bufferSize) { | ||||||
|   return serialize<JsonSerializer>(source, buffer, bufferSize); |   return serialize<JsonSerializer>(source, buffer, bufferSize); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename TSource> | inline size_t measureJson(VariantConstRef source) { | ||||||
| size_t measureJson(const TSource &source) { |  | ||||||
|   return measure<JsonSerializer>(source); |   return measure<JsonSerializer>(source); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -70,19 +70,17 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> { | |||||||
|   uint8_t _nesting; |   uint8_t _nesting; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| template <typename TSource, typename TDestination> | template <typename TDestination> | ||||||
| size_t serializeJsonPretty(const TSource &source, TDestination &destination) { | size_t serializeJsonPretty(VariantConstRef source, TDestination &destination) { | ||||||
|   return serialize<PrettyJsonSerializer>(source, destination); |   return serialize<PrettyJsonSerializer>(source, destination); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename TSource> | inline size_t serializeJsonPretty(VariantConstRef source, void *buffer, | ||||||
| size_t serializeJsonPretty(const TSource &source, void *buffer, |                                   size_t bufferSize) { | ||||||
|                            size_t bufferSize) { |  | ||||||
|   return serialize<PrettyJsonSerializer>(source, buffer, bufferSize); |   return serialize<PrettyJsonSerializer>(source, buffer, bufferSize); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename TSource> | inline size_t measureJsonPretty(VariantConstRef source) { | ||||||
| size_t measureJsonPretty(const TSource &source) { |  | ||||||
|   return measure<PrettyJsonSerializer>(source); |   return measure<PrettyJsonSerializer>(source); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -197,19 +197,17 @@ class MsgPackSerializer : public Visitor<size_t> { | |||||||
|   CountingDecorator<TWriter> _writer; |   CountingDecorator<TWriter> _writer; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| template <typename TSource, typename TDestination> | template <typename TDestination> | ||||||
| inline size_t serializeMsgPack(const TSource& source, TDestination& output) { | inline size_t serializeMsgPack(VariantConstRef source, TDestination& output) { | ||||||
|   return serialize<MsgPackSerializer>(source, output); |   return serialize<MsgPackSerializer>(source, output); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename TSource> | inline size_t serializeMsgPack(VariantConstRef source, void* output, | ||||||
| inline size_t serializeMsgPack(const TSource& source, void* output, |  | ||||||
|                                size_t size) { |                                size_t size) { | ||||||
|   return serialize<MsgPackSerializer>(source, output, size); |   return serialize<MsgPackSerializer>(source, output, size); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename TSource> | inline size_t measureMsgPack(VariantConstRef source) { | ||||||
| inline size_t measureMsgPack(const TSource& source) { |  | ||||||
|   return measure<MsgPackSerializer>(source); |   return measure<MsgPackSerializer>(source); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,8 +8,8 @@ | |||||||
|  |  | ||||||
| namespace ARDUINOJSON_NAMESPACE { | namespace ARDUINOJSON_NAMESPACE { | ||||||
|  |  | ||||||
| template <template <typename> class TSerializer, typename TSource> | template <template <typename> class TSerializer> | ||||||
| size_t measure(const TSource &source) { | size_t measure(VariantConstRef source) { | ||||||
|   DummyWriter dp; |   DummyWriter dp; | ||||||
|   TSerializer<DummyWriter> serializer(dp); |   TSerializer<DummyWriter> serializer(dp); | ||||||
|   return source.accept(serializer); |   return source.accept(serializer); | ||||||
|   | |||||||
| @@ -8,30 +8,28 @@ | |||||||
|  |  | ||||||
| namespace ARDUINOJSON_NAMESPACE { | namespace ARDUINOJSON_NAMESPACE { | ||||||
|  |  | ||||||
| template <template <typename> class TSerializer, typename TSource, | template <template <typename> class TSerializer, typename TWriter> | ||||||
|           typename TWriter> | size_t doSerialize(VariantConstRef source, TWriter writer) { | ||||||
| size_t doSerialize(const TSource &source, TWriter writer) { |  | ||||||
|   TSerializer<TWriter> serializer(writer); |   TSerializer<TWriter> serializer(writer); | ||||||
|   return source.accept(serializer); |   return source.accept(serializer); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <template <typename> class TSerializer, typename TSource, | template <template <typename> class TSerializer, typename TDestination> | ||||||
|           typename TDestination> | size_t serialize(VariantConstRef source, TDestination &destination) { | ||||||
| size_t serialize(const TSource &source, TDestination &destination) { |  | ||||||
|   Writer<TDestination> writer(destination); |   Writer<TDestination> writer(destination); | ||||||
|   return doSerialize<TSerializer>(source, writer); |   return doSerialize<TSerializer>(source, writer); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <template <typename> class TSerializer, typename TSource> | template <template <typename> class TSerializer> | ||||||
| typename enable_if<!TSerializer<StaticStringWriter>::producesText, size_t>::type | typename enable_if<!TSerializer<StaticStringWriter>::producesText, size_t>::type | ||||||
| serialize(const TSource &source, void *buffer, size_t bufferSize) { | serialize(VariantConstRef source, void *buffer, size_t bufferSize) { | ||||||
|   StaticStringWriter writer(reinterpret_cast<char *>(buffer), bufferSize); |   StaticStringWriter writer(reinterpret_cast<char *>(buffer), bufferSize); | ||||||
|   return doSerialize<TSerializer>(source, writer); |   return doSerialize<TSerializer>(source, writer); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <template <typename> class TSerializer, typename TSource> | template <template <typename> class TSerializer> | ||||||
| typename enable_if<TSerializer<StaticStringWriter>::producesText, size_t>::type | typename enable_if<TSerializer<StaticStringWriter>::producesText, size_t>::type | ||||||
| serialize(const TSource &source, void *buffer, size_t bufferSize) { | serialize(VariantConstRef source, void *buffer, size_t bufferSize) { | ||||||
|   StaticStringWriter writer(reinterpret_cast<char *>(buffer), bufferSize); |   StaticStringWriter writer(reinterpret_cast<char *>(buffer), bufferSize); | ||||||
|   size_t n = doSerialize<TSerializer>(source, writer); |   size_t n = doSerialize<TSerializer>(source, writer); | ||||||
|   // add null-terminator for text output (not counted in the size) |   // add null-terminator for text output (not counted in the size) | ||||||
| @@ -40,14 +38,13 @@ serialize(const TSource &source, void *buffer, size_t bufferSize) { | |||||||
|   return n; |   return n; | ||||||
| } | } | ||||||
|  |  | ||||||
| template <template <typename> class TSerializer, typename TSource, | template <template <typename> class TSerializer, typename TChar, size_t N> | ||||||
|           typename TChar, size_t N> |  | ||||||
| #if defined _MSC_VER && _MSC_VER < 1900 | #if defined _MSC_VER && _MSC_VER < 1900 | ||||||
| typename enable_if<sizeof(remove_reference<TChar>::type) == 1, size_t>::type | typename enable_if<sizeof(remove_reference<TChar>::type) == 1, size_t>::type | ||||||
| #else | #else | ||||||
| typename enable_if<sizeof(TChar) == 1, size_t>::type | typename enable_if<sizeof(TChar) == 1, size_t>::type | ||||||
| #endif | #endif | ||||||
| serialize(const TSource &source, TChar (&buffer)[N]) { | serialize(VariantConstRef source, TChar (&buffer)[N]) { | ||||||
|   return serialize<TSerializer>(source, buffer, N); |   return serialize<TSerializer>(source, buffer, N); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user