Skip to content

Add Chunk::object_offsets() read-only accessor#77

Open
gpradofe wants to merge 1 commit intotypst:mainfrom
gpradofe:add-chunk-object-offsets
Open

Add Chunk::object_offsets() read-only accessor#77
gpradofe wants to merge 1 commit intotypst:mainfrom
gpradofe:add-chunk-object-offsets

Conversation

@gpradofe
Copy link
Copy Markdown

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.

This PR adds a small object_offsets() accessor that returns the (Ref, byte_offset) pairs alongside the byte buffer, which is useful when:

  • Doing piecewise / partial serialization (e.g. writing a large PDF in multiple passes and needing to recover where each object sits inside a chunk).
  • Indexing into 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

  • Added test_chunk_object_offsets verifying the returned offsets match refs() and that each offset points at a real N 0 obj header inside the chunk's byte buffer.
  • cargo test passes.
  • cargo clippy --all-targets --all-features clean under -Dwarnings.
  • cargo fmt --check clean.

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant