Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::DocumentDecoder Class Reference

#include <document_encoding.hpp>

Public Member Functions

 DocumentDecoder (DocumentDecoderOptions options={}) noexcept
std::optional< DocumentDecoderCheckpoint > checkpoint () const noexcept
DocumentDecodeResult feed (std::span< const std::byte > input, std::uint64_t offset, bool final, std::span< DecodedScalar > output) noexcept
DocumentEncoding encoding () const noexcept
std::uint8_t bomLength () const noexcept
bool bomMismatch () const noexcept

Static Public Member Functions

static DocumentDecoder restore (const DocumentDecoderCheckpoint &checkpoint) noexcept
static DocumentDecoderLocalResult localCheckpoint (const DocumentDecoderCheckpoint &origin, std::span< const std::byte > window, std::uint64_t windowOffset, std::uint64_t anchorByteOffset, bool finalWindow=false) noexcept

Static Public Attributes

static constexpr std::size_t LOCAL_WINDOW_BYTES = 8
 Maximum original bytes admitted by localCheckpoint().

Detailed Description

Incrementally decode a single contiguous stream beginning at byte zero.

The caller owns input and output and may discard them on return. The decoder retains at most four input bytes and is not safe for concurrent access. Offsets must equal the starting offset plus inputConsumed from prior successful calls. The starting offset is zero for a new decoder or the checkpoint offset on restore. final denotes confirmed EOF, not temporary absence of bytes. A matching BOM at byte zero is omitted and reported by bomLength(); a conflicting BOM is retained as input and reported by bomMismatch(). The explicit choice takes precedence over a BOM, followed by the hint. No selection is an error.

NEED_INPUT requests another chunk; OUTPUT_FULL requests output space; WORK_LIMIT requests another call with the unconsumed suffix; DONE marks EOF. These statuses commit state and report consumed/produced counts. MALFORMED, ENCODING_UNRESOLVED, INVALID_OFFSET and UNSUPPORTED_POLICY leave state unchanged, return zero counts and invalidate output written during that call. STRICT_MODE reports the first malformed span; REPLACE emits U+FFFD tagged as replacement. ESCAPE and a zero work limit are unsupported. A zero-capacity output may return OUTPUT_FULL after buffering a bounded BOM prefix.

Each scalar retains its original byte interval. Noncharacters are preserved; valid controls are not sanitized and require safe rendering separately. localCheckpoint() proves a bounded cold restart boundary; it does not certify the omitted prefix's validity. Grapheme, line and cell mapping remain separate.

Constructor & Destructor Documentation

◆ DocumentDecoder()

portals::DocumentDecoder::DocumentDecoder ( DocumentDecoderOptions options = {})
explicitnoexcept

Create a new stream decoder. A zero work limit or ESCAPE is unsupported.

Parameters
optionsEncoding selection, error policy and input work limit.

Member Function Documentation

◆ bomLength()

std::uint8_t portals::DocumentDecoder::bomLength ( ) const
inlinenoexcept
Returns
Size of a matching BOM omitted at the original stream start.

◆ bomMismatch()

bool portals::DocumentDecoder::bomMismatch ( ) const
inlinenoexcept
Returns
True if an explicit choice conflicted with the original BOM.

◆ checkpoint()

std::optional< DocumentDecoderCheckpoint > portals::DocumentDecoder::checkpoint ( ) const
noexcept

Capture only after selection, with no pending bytes, before EOF.

Returns
Opaque boundary state, or an empty optional when capture is unavailable.

◆ encoding()

DocumentEncoding portals::DocumentDecoder::encoding ( ) const
inlinenoexcept
Returns
Selected encoding, or UNRESOLVED before selection.

◆ feed()

DocumentDecodeResult portals::DocumentDecoder::feed ( std::span< const std::byte > input,
std::uint64_t offset,
bool final,
std::span< DecodedScalar > output )
noexcept

Decode a bounded contiguous input chunk into caller-owned scalar records.

Parameters
inputBorrowed bytes contiguous with the committed input.
offsetAbsolute offset of the first input byte.
finalTrue only when the end of input is confirmed.
outputCaller-owned storage for decoded scalars.
Returns
Committed counts and status, or a typed failure with error location.

◆ localCheckpoint()

DocumentDecoderLocalResult portals::DocumentDecoder::localCheckpoint ( const DocumentDecoderCheckpoint & origin,
std::span< const std::byte > window,
std::uint64_t windowOffset,
std::uint64_t anchorByteOffset,
bool finalWindow = false )
staticnoexcept

Prove the scalar/subpart containing an anchor without traversing its omitted prefix.

Parameters
originReal opaque checkpoint after original encoding/BOM resolution, qualified by the caller against the same immutable source revision and decoding policy.
windowAt most LOCAL_WINDOW_BYTES original bytes, borrowed only for this call.
windowOffsetAbsolute original-byte offset of the local window, which may be unaligned.
anchorByteOffsetExact user anchor within the inclusive window interval. It stays unchanged; the returned scalar-start projection can precede it, or follow it inside an omitted BOM.
finalWindowTrue only when window end is proven source EOF, never temporary absence.
Returns
Owning proof/error result. Only READY supplies a real checkpoint for restore(); AT_END supplies none, so odd EOF tails cannot become continuation alignment after append. Missing local context returns NEED_PREFIX/NEED_SUFFIX. STRICT_MODE validates the selected subpart and resumed reads, not the omitted whole prefix. The origin is never mutated and effective encoding, original BOM decision, policy and work limit are preserved.

◆ restore()

DocumentDecoder portals::DocumentDecoder::restore ( const DocumentDecoderCheckpoint & checkpoint)
staticnoexcept

Resume a previously captured boundary without probing for another BOM.

Parameters
checkpointBoundary state bound by the caller to the source revision.
Returns
Decoder restored to the captured boundary.

The documentation for this class was generated from the following file: