#[non_exhaustive]pub enum Provenance {
File(ByteSpan),
RecoveredFile(ByteSpan),
ObjectStream {
container: ObjId,
index: u32,
},
}Expand description
Where an indirect object’s definition physically lives in the loaded file — the provenance discriminator the minimal-diff writer needs (ARCHITECTURE.md §5; decision 001 §6.1 item 1).
§Why this is an enum and not a ByteSpan
§5’s contract — “an object pdfcer did not logically modify re-emits
its source bytes verbatim, or is omitted entirely” — is only
expressible for an object defined at file level as
N G obj … endobj. A PDF 1.5 object compressed inside an object
stream (§7.5.7) has no byte range of its own in the file at all:
its bytes exist only inside its container’s encoded stream data,
interleaved with the other objects of that container, and are not
even recoverable without running the container’s filter chain.
Modelling that as “a span that happens to be wrong/absent” would be a lie the writer could not detect. Making it a type-level distinction forces every future save path to decide consciously what a compressed object means for it:
- Incremental save, object untouched — emit nothing. The container object is itself span-backed and untouched, so the whole prior revision stays byte-identical. No decision needed.
- Incremental save, object modified — the object cannot be patched in place; the writer must either re-emit it as a new file-level object in the update section (legal: an object may move out of an object stream between revisions) or write a whole new container. Both are correct; the choice is the writer’s, and it must be made knowingly.
- Full rewrite — re-serialize from values; there is nothing verbatim to preserve.
The ObjectStream variant carries the
container id and the index within it precisely so the writer has the
facts to make that choice without re-deriving them from the xref.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
File(ByteSpan)
Defined at file level. The span covers the complete
definition — from the first byte of the object number through
the last byte of endobj — so an untouched object re-emits (or,
in incremental save, retains) exactly its source bytes.
RecoveredFile(ByteSpan)
Defined at file level at this span, but the retained bytes are internally inconsistent and therefore must NOT be re-emitted verbatim — the parsed value is authoritative, not the source bytes.
Set in exactly one situation: cross-reference recovery re-derived a
stream’s extent from its endstream keyword because the stored
/Length was unusable
(StreamLengthPolicy::RecoverFromEndstream).
The span’s bytes then say one length while the parsed
Stream::data_span says another, and copying them through would
make pdfcer write out the very inconsistency it just recovered
from — producing a file pdfcer itself would refuse to reload. The
writer re-serializes instead, which regenerates /Length from the
actual data (writer::serialize’s “/Length is always recomputed,
never trusted”).
This is a third state rather than a flag on
File for the same reason
ObjectStream is: it forces every save
path to decide consciously what it means, instead of leaving a
“span that happens to be untrustworthy” the writer cannot detect.
file_span still returns the span — the
bytes are genuinely there, and a consumer that wants to show the
definition’s location (the CLI’s object listing) is still right to
ask. Only re-emission is affected.
ObjectStream
Compressed inside an object stream (§7.5.7); reached through a type-2 cross-reference entry (§7.5.8.3 Table 18). There is no file-level span — see the type docs.
Implementations§
Source§impl Provenance
impl Provenance
Sourcepub const fn file_span(self) -> Option<ByteSpan>
pub const fn file_span(self) -> Option<ByteSpan>
The object’s verbatim byte range in the retained source buffer,
or None for a compressed object (which has none).
This is the accessor the writer uses; returning Option rather
than a sentinel is the whole point of the enum (type docs).
Sourcepub const fn is_verbatim_safe(self) -> bool
pub const fn is_verbatim_safe(self) -> bool
Whether this object’s retained bytes may be copied through to a saved file verbatim.
True only for File. A
RecoveredFile object has bytes but
they contradict the parsed value, and an
ObjectStream object has no file-level
bytes at all — both must be re-serialized from values.
Exists so the writer asks the question it actually means. Testing
file_span().is_some() would silently start copying
self-contradictory bytes the day the third variant appeared, which
is precisely the “span that happens to be wrong” failure mode this
enum was designed to make impossible.