View Source Pdf.Reader.ObjectResolver (ExPDF v1.0.1)
Lazy indirect-object resolver with Map-based cache.
Per the design (sdd/pdf-reader-core/design § 5 "Lazy Resolution Contract"):
- Cache: a plain
Mapon%Pdf.Reader.Document{}.cache. No GenServer. Key:{obj_num, gen_num}. Value: the resolved Elixir term. Signature:
resolve(doc, {:ref, n, g}) :: {:ok, value, doc} | {:error, reason}. The returneddoccarries the updated cache. The caller threadsdocforward for cache benefit; dropping the updated doc still yields correct results on the next call (re-parse, same value — the binary is immutable).- Idempotent: calling
resolve/2twice on the same ref with the same doc returns the same value. The cache is a hint, not state.
Resolution paths
- Cache hit:
Map.get(doc.cache, {n, g})→ immediate return. - In-use (classic): look up
{n, g}indoc.xref→{:in_use, offset, _gen}. Slicebinary_part(doc.binary, offset, ...), runParser.parse_object/1. - Compressed (ObjStm): look up
{n, g}→{:compressed, objstm_n, index}. Recursivelyresolve(doc, {:ref, objstm_n, 0}), decode filters, thenObjectStream.fetch/3. - Free / absent:
{:error, {:unresolved_ref, {n, g}}}.
Ref chasing
resolve/2 does NOT automatically follow nested refs. If a resolved value
is itself {:ref, _, _}, the caller decides whether to chase it. This avoids
infinite loops on circular references and keeps the interface predictable.
Summary
Functions
Resolve an indirect object reference to its value.
Functions
@spec resolve(Pdf.Reader.Document.t(), {:ref, pos_integer(), non_neg_integer()}) :: {:ok, term(), Pdf.Reader.Document.t()} | {:error, term()}
Resolve an indirect object reference to its value.
Returns {:ok, value, updated_doc} on success, where updated_doc has
the resolved value cached. Returns {:error, reason} on failure.
The caller should thread the returned doc forward to benefit from caching
on subsequent resolutions.
Error reasons
{:error, {:unresolved_ref, {n, g}}}— ref is absent from xref or is a free entry.{:error, :malformed}— parse failure.{:error, {:unsupported_filter, name}}— propagated from filter chain.