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

input_adapter not user extensible #1813

Closed
abrownsword opened this issue Oct 25, 2019 · 6 comments · Fixed by #2145
Closed

input_adapter not user extensible #1813

abrownsword opened this issue Oct 25, 2019 · 6 comments · Fixed by #2145

Comments

@abrownsword
Copy link

abrownsword commented Oct 25, 2019

I need to implement a slight variation on one of the standard input adapters, but I have no way to implement the input_adapter_protocol and then connect it to the detail::input_adapter. This is basically equivalent to my earlier issue about making output_adapter extensible (#1534 ) as well.

@stale
Copy link

stale bot commented Nov 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Nov 24, 2019
@stale stale bot closed this as completed Dec 1, 2019
@jzakrzewski
Copy link

Would be a great thing to have!

@abrownsword
Copy link
Author

Would like to keep this issue alive and see it addressed. Input data very often comes from sources which are not std::istream or in-memory strings.

@nlohmann nlohmann reopened this Apr 19, 2020
@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Apr 19, 2020
@nlohmann
Copy link
Owner

This may be fixed in #1950.

@stale
Copy link

stale bot commented May 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 19, 2020
@nlohmann nlohmann removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 22, 2020
@FrancoisChabot
Copy link
Contributor

FrancoisChabot commented May 26, 2020

Here's how I think this should look:

I suggest adding the following overload to the parse function(s):

template<typename IteratorType>
json parse(IteratorType begin, IteratorType end, bool strict);

Internally, this would check if std::iterator_traits<IteratorType>::value_type is int8_t , uint8_t, or wchar_t, and properly instantiate a matching input adapter.

A user-defined input would just be a matter of creating a user-defined iterator.

I will also reiterate my opinion that the brace-enclosed syntax should be deprecated, as its existence is predicated on the implicit construction of a library-internal type, which should not be part of the documentation.

char* raw = ...;
std::size_t len = ...;
auto data = json::parse({raw, len});   // Current, effectively undocumented.
auto data = json::parse(raw, raw + len); // new, better syntax 

@nlohmann nlohmann linked a pull request Jun 5, 2020 that will close this issue
4 tasks
@nlohmann nlohmann self-assigned this Jun 5, 2020
@nlohmann nlohmann added this to the Release 3.8.0 milestone Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants