Skip to content

Add Iterator.Buffered() method to mimic json.Decoder #712

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

Closed
wants to merge 34 commits into from

Conversation

mhr3
Copy link

@mhr3 mhr3 commented Jun 6, 2025

Summary

This PR adds a new Buffered() method to the Iterator that mimics the behavior of Go's standard library json.Decoder.Buffered().

Changes

✨ New Feature: Iterator.Buffered() method

  • Added Iterator.Buffered() io.Reader - Returns a reader of the data remaining in the Iterator's buffer
  • Standard library compatibility - Matches the behavior of json.Decoder.Buffered() from Go's standard library

🐛 Bug Fixes: Error Position Reporting

Fixed multiple instances of missing iter.unreadByte() calls, which allow using the Buffered more effectively.

These fixes ensure that when parsing errors occur, the iterator can return buffer including the problematic character rather than the character after it.

Use Cases

The Buffered() method enables:

  • Incremental parsing: Process JSON incrementally while preserving unread data
  • Parser chaining: Pass remaining data to other parsers or processors
  • Debugging: Inspect remaining unparsed data for troubleshooting

Testing

  • All new functionality is covered by comprehensive unit tests
mhr3 and others added 30 commits September 9, 2020 13:50
Optimize string processing
Backport fixes from upstream
plus do some API cleanups
Replace ReadStringAsSlice with ReadRawString
add ReadStringAsSlice compatibility with upstream
@mhr3 mhr3 closed this Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants