Add Chunk::object_offsets() read-only accessor#77
Open
gpradofe wants to merge 1 commit intotypst:mainfrom
Open
Add Chunk::object_offsets() read-only accessor#77gpradofe wants to merge 1 commit intotypst:mainfrom
Chunk::object_offsets() read-only accessor#77gpradofe wants to merge 1 commit intotypst:mainfrom
Conversation
`Chunk` already exposes `refs()` to iterate the top-level indirect object references in order, and `as_bytes()` to look at the raw buffer. The byte offset of each object is already tracked internally (`pub(crate) offsets: Vec<(Ref, usize)>`) but is not exposed. Add a small `object_offsets()` accessor that returns the `(Ref, offset)` pairs alongside the byte buffer. This is useful for: - Piecewise / partial serialization (e.g. writing a large PDF in multiple passes and needing to recover where each object sits). - External object stores that want to index into `as_bytes()` directly and record the object positions alongside the bytes. The accessor is read-only and exposes data that was already derivable from the public API plus a linear scan; it changes no invariants. Includes a test verifying that the returned offsets match `refs()` and that each points at a real `N 0 obj` header inside the chunk's byte buffer.
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.
Chunkalready exposesrefs()to iterate the top-level indirect object references in order, andas_bytes()to look at the raw buffer. The byte offset of each object is already tracked internally (pub(crate) offsets: Vec<(Ref, usize)>) but is not exposed.This PR adds a small
object_offsets()accessor that returns the(Ref, byte_offset)pairs alongside the byte buffer, which is useful when:as_bytes()directly from an external object store or cache that wants to record object positions alongside the bytes.The accessor is read-only and exposes data that's already derivable from the public API plus a linear scan; it doesn't change any invariants.
Test plan
test_chunk_object_offsetsverifying the returned offsets matchrefs()and that each offset points at a realN 0 objheader inside the chunk's byte buffer.cargo testpasses.cargo clippy --all-targets --all-featuresclean under-Dwarnings.cargo fmt --checkclean.