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

Bounded streaming decoder for a deliberately small 7-bit VT input profile. More...

#include <input.hpp>

Public Member Functions

 InputDecoder (const InputDecoder &)=delete
 Stateful streams cannot be copied.
InputDecoder & operator= (const InputDecoder &)=delete
 Stateful streams cannot be copied.
 InputDecoder (InputDecoder &&other) noexcept=default
 Moved-from object must be reset before use.
InputDecoder & operator= (InputDecoder &&other) noexcept=default
 Reset moved-from object before reuse.
std::expected< InputStep, InputError > next (std::string_view bytes, InputTime now)
 Pull at most one event or protocol report, accepting at most work_bytes from a borrowed view.
std::expected< InputStep, InputError > finish (InputTime now)
 End the stream, flushing at most one pending event per call. Repeat until finished/failed. next() then returns closed; reset starts a new session. Monotonic time and allocation/error contracts match next(). No input is consumed.
std::optional< InputTime > deadline () const noexcept
 Return the next decode deadline, or none in ground/closed/failed state. Pending events must be drained before waiting. No allocation or mutation.
std::expected< void, InputError > expectReplies (InputProbeWindow window) noexcept
 Replace expected replies; valid only in ground with no pending event. Returns INVALID_WINDOW if deadline <= opens_at or not at a sequence boundary. Does not change time, own a query, send bytes, or authenticate future candidates.
void setPointerContext (InputPointerContext context) noexcept
 Set the owning context for subsequently started CSI sequences, without resetting partial input.
void reset () noexcept
 Drop pending input/window/time/offset and recover at an explicit new session boundary. Options remain. Frees retained paste; does not invalidate already returned events.

Static Public Member Functions

static std::expected< InputDecoder, InputError > create (InputOptions options={})
 Validate options and create an empty decoder. No allocations or I/O.

Detailed Description

Bounded streaming decoder for a deliberately small 7-bit VT input profile.

One executor owns an instance; synchronize any transfer between threads. Independent instances may run concurrently. No callbacks, I/O, shared globals or terminal mode changes occur. Events and protocol reports own their data; input views are borrowed only during next(). Storage is O(max_paste_bytes) plus fixed scratch and one pending issue. Caller must bound its own retained events. Allocation failures propagate, leaving the decoder failed until reset; no partial paste is delivered.

Note
For identical timestamps and feed/finish/window schedules, event order does not depend on chunk boundaries. Preserve timestamps when resubmitting suffixes. Deadlines saturate at UINT64_MAX; now >= deadline expires before accepting bytes. The legacy protocol cannot distinguish typed/forged replies or paste end markers.

Constructor & Destructor Documentation

◆ InputDecoder()

portals::InputDecoder::InputDecoder ( InputDecoder && other)
defaultnoexcept

Moved-from object must be reset before use.

Parameters
otherStream state and buffered bytes to transfer; reset it before reuse.

Member Function Documentation

◆ create()

std::expected< InputDecoder, InputError > portals::InputDecoder::create ( InputOptions options = {})
staticnodiscard

Validate options and create an empty decoder. No allocations or I/O.

Parameters
optionsWork, storage and timeout bounds for the lifetime of this stream.
Returns
An empty decoder, or INVALID_OPTIONS when a bound is outside its documented range.

◆ deadline()

std::optional< InputTime > portals::InputDecoder::deadline ( ) const
nodiscardnoexcept

Return the next decode deadline, or none in ground/closed/failed state. Pending events must be drained before waiting. No allocation or mutation.

Returns
Next absolute decoder timeout, or nullopt when waiting on time cannot advance decoding.

◆ expectReplies()

std::expected< void, InputError > portals::InputDecoder::expectReplies ( InputProbeWindow window)
nodiscardnoexcept

Replace expected replies; valid only in ground with no pending event. Returns INVALID_WINDOW if deadline <= opens_at or not at a sequence boundary. Does not change time, own a query, send bytes, or authenticate future candidates.

Parameters
windowExpected single-use reply kinds, correlation generation and half-open time interval.
Returns
Success, or INVALID_WINDOW when the interval or current stream boundary is invalid.

◆ finish()

std::expected< InputStep, InputError > portals::InputDecoder::finish ( InputTime now)
nodiscard

End the stream, flushing at most one pending event per call. Repeat until finished/failed. next() then returns closed; reset starts a new session. Monotonic time and allocation/error contracts match next(). No input is consumed.

Parameters
nowMonotonic timestamp, not earlier than the last accepted call.
Returns
At most one final event and its stop reason, or a call error with no input consumed.

◆ next()

std::expected< InputStep, InputError > portals::InputDecoder::next ( std::string_view bytes,
InputTime now )
nodiscard

Pull at most one event or protocol report, accepting at most work_bytes from a borrowed view.

Parameters
bytesUnconsumed input suffix; never retained as a view.
nowMonotonic arrival timestamp; equal values are allowed.
Returns
Consumed count and one owning event or report with its stop reason, or a call error before consuming input.
Note
EVENT always contains event; PROTOCOL always contains protocol and no event. Handle either result before resubmitting the suffix, including at the work limit. Empty input advances time and drains pending events. Repeat with an empty view until NEED_INPUT/failed to drain. Errors do not consume bytes. No invalidation of earlier events or reports. Allocation exceptions require reset (discard session suffix).

◆ operator=()

InputDecoder & portals::InputDecoder::operator= ( InputDecoder && other)
defaultnoexcept

Reset moved-from object before reuse.

Parameters
otherStream state that replaces the current, unfinished stream.
Returns
This decoder after memberwise state transfer; reset a moved-from source before reuse.

◆ setPointerContext()

void portals::InputDecoder::setPointerContext ( InputPointerContext context)
noexcept

Set the owning context for subsequently started CSI sequences, without resetting partial input.

Parameters
contextProven wire units and currently usable dimensions; zero dimensions suppress unsafe pixel samples.
Note
A CSI retains its start context. No allocation, callbacks or I/O; earlier results remain independent.

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