feat: Add Reader.RawValue and Reader.Offset for raw value capture - #50
Merged
Conversation
Port of the v3 RawValue/Offset work (#45) to the v4 module line. RawValue returns the next JSON value's raw bytes as a zero-copy slice of the input (cap == len), fully validated: scalars via the tokenizer, containers via a string-aware boundary scan plus encoding/json validation of the captured span. Offset returns the current byte position for capturing a value parsed in place. v4 has no easyjson backend, so the port drops the build tags and the easyjson-specific comments/placeholder that the v3 change carried; the logic is otherwise identical.
keelerm84
marked this pull request as ready for review
July 29, 2026 18:26
kinyoklion
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of the v3 RawValue/Offset work (#45) to the v4 module line.
RawValue returns the next JSON value's raw bytes as a zero-copy slice of the
input (cap == len), fully validated: scalars via the tokenizer, containers via a
string-aware boundary scan plus encoding/json validation of the captured span.
Offset returns the current byte position for capturing a value parsed in place.
v4 has no easyjson backend, so the port drops the build tags and the
easyjson-specific comments/placeholder that the v3 change carried; the logic is
otherwise identical.
Note
Medium Risk
New parsing surface on the core tokenizer with container boundary scanning; behavior is heavily tested and additive, but mistakes could affect JSON acceptance or slice aliasing guarantees.
Overview
Adds
Reader.RawValue()andReader.Offset()so callers can capture the next JSON value as a zero-copy slice of the input (cap == len), or slice the buffer around an in-place parse withoutRawValue’s extra container scan.RawValuevalidates scalars via the existing RFC 8259 tokenizer; for arrays/objects it uses a string-aware delimiter scan and thenencoding/json.Validon the captured span. Unread-token paths (e.g. afterNull()probes) are handled explicitly. A newerrMsgInvalidValuebacks invalid container content.Offsetreports the next consume position (or the start of a pushed-back token), documented for start/end span capture with JSON whitespace trimming.Coverage includes unit tests,
encoding/jsondifferential/oracle tests, generative runs, and scalar grammar fuzzing.Reviewed by Cursor Bugbot for commit c72dc8d. Bugbot is set up for automated code reviews on this repo. Configure here.