Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable String reader when Stream is enabled and String derives from Stream #1341

Closed
wants to merge 1 commit into from

Conversation

d-a-v
Copy link
Contributor

@d-a-v d-a-v commented Aug 9, 2020

This is related to PR esp8266/Arduino#6979 (specifically this).
It is opened for discussion.

This would solve this error:

sketch/StringExample.ino.cpp:
In file included from ArduinoJson/src/ArduinoJson/Json/JsonDeserializer.hpp:7,
                 from ArduinoJson/src/ArduinoJson.hpp:34,
                 from ArduinoJson/src/ArduinoJson.h:9,
                 from ArduinoJson/examples/StringExample/StringExample.ino:13:
ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp: In instantiation of 'ArduinoJson6161_11::DeserializationError ArduinoJson6161_11::deserialize(ArduinoJson6161_11::JsonDocument&, TStream&, ArduinoJson6161_11::NestingLimit, TFilter) [with TDeserializer = ArduinoJson6161_11::JsonDeserializer; TStream = String; TFilter = ArduinoJson6161_11::AllowAllFilter]':
ArduinoJson/src/ArduinoJson/Json/JsonDeserializer.hpp:676:39:   required from 'ArduinoJson6161_11::DeserializationError ArduinoJson6161_11::deserializeJson(ArduinoJson6161_11::JsonDocument&, TInput&, ArduinoJson6161_11::NestingLimit) [with TInput = String]'
ArduinoJson/examples/StringExample/StringExample.ino:22:29:   required from here
ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp:61:19: error: ambiguous template instantiation for 'struct ArduinoJson6161_11::Reader<String, void>'
   61 |   Reader<TStream> reader(input);
      |                   ^~~~~~
In file included from ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp:43,
                 from ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp:10,
                 from ArduinoJson/src/ArduinoJson/Json/JsonDeserializer.hpp:7,
                 from ArduinoJson/src/ArduinoJson.hpp:34,
                 from ArduinoJson/src/ArduinoJson.h:9,
                 from ArduinoJson/examples/StringExample/StringExample.ino:13:
ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp:12:8: note: candidates are: 'template<class TSource> struct ArduinoJson6161_11::Reader<TSource, typename ArduinoJson6161_11::enable_if<ArduinoJson6161_11::is_base_of<Stream, TSource>::value>::type> [with TSource = String]'
   12 | struct Reader<TSource,
      |        ^~~~~~~~~~~~~~~
   13 |               typename enable_if<is_base_of<Stream, TSource>::value>::type> {
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp:47,
                 from ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp:10,
                 from ArduinoJson/src/ArduinoJson/Json/JsonDeserializer.hpp:7,
                 from ArduinoJson/src/ArduinoJson.hpp:34,
                 from ArduinoJson/src/ArduinoJson.h:9,
                 from ArduinoJson/examples/StringExample/StringExample.ino:13:
ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp:10:8: note:                 'template<class TSource> struct ArduinoJson6161_11::Reader<TSource, typename ArduinoJson6161_11::enable_if<ArduinoJson6161_11::is_base_of<String, TSource>::value>::type> [with TSource = String]'
   10 | struct Reader<TSource,
      |        ^~~~~~~~~~~~~~~
   11 |               typename enable_if<is_base_of< ::String, TSource>::value>::type>
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ArduinoJson/src/ArduinoJson/Json/JsonDeserializer.hpp:7,
                 from ArduinoJson/src/ArduinoJson.hpp:34,
                 from ArduinoJson/src/ArduinoJson.h:9,
                 from ArduinoJson/examples/StringExample/StringExample.ino:13:
ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp:61:19: error: 'ArduinoJson6161_11::Reader<String, void> reader' has incomplete type
   61 |   Reader<TStream> reader(input);
      |                   ^~~~~~
Using library ArduinoJson at version 6.16.1 in folder: ArduinoJson 

@bblanchon
Copy link
Owner

You mean String derives from Stream 😮
What the hell is this?!

@d-a-v d-a-v changed the title Disable String reader when Stream is enabled and String is Stream Disable String reader when Stream is enabled and String derives from Stream Aug 9, 2020
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.289% when pulling a70411f on d-a-v:streamTo6 into 61a5273 on bblanchon:6.x.

@d-a-v
Copy link
Contributor Author

d-a-v commented Aug 9, 2020

What the hell is this?!

Only a proposal on esp8266 Arduino for now.

Is that really such a hell ?
Wouldn't a String be a Stream from which we could read, or to which we could write ?
That'd make Strings usable on any virtual (the arduino way) function designed for Streams, without needing to overload, or copy to intermediate buffer.

@bblanchon
Copy link
Owner

bblanchon commented Aug 9, 2020

You don't seem to realize that the ESP8266 Core was copied from the AVR core, and there are dozens of other duplicates out there.
If you change the interface like this, you're going to break a lot of code.

If you want to use a String as a Stream, simply use an adapter like StringStream.

@bblanchon bblanchon closed this Aug 9, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants