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

Feature: Support string prefix parsing #995

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mullr
Copy link

@mullr mullr commented Mar 7, 2023

This adds support for parsing json from the prefix of a string. It does so via two small api additions:

  • Deserializer now has the into_reader associated function, which consume the deserializer and returns reader it has been using.

  • StrRead and SliceRead now have the index associated function, which reports the byte index of the data which will be read next.

These can be used to parse a single value (or multiple values) from an input string or buffer, and then recover the next byte position from the reader. It allows the json parser to be easily integrated into an outer parser, where the JSON data is sitting inside some larger non-JSON context.

This adds support for parsing json from the prefix of a string. It
does so via two small api additions:

- Deserializer now has the `into_reader` associated function, which
  consume the deserializer and returns reader it has been using.

- StrRead and SliceRead now have the `index` associated function,
  which reports the byte index of the data which will be read next.

These can be used to parse a single value (or multiple values) from
an input string or buffer, and then recover the next byte position
from the reader. It allows the json parser to be easily integrated
into an outer parser, where the JSON data is sitting inside some
larger non-JSON context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant