Documentation
¶
Overview ¶
Package snapshot provides typed state snapshots + dirty-field tracking for delta-encoded replication. Producers track per-consumer baselines; each Append yields only the fields changed since that consumer's last acknowledged frame.
Also ships Ring[S], a fixed-size circular buffer indexed by frame number for lag-compensation lookups.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder[S any] interface { Encode(state, baseline S, mask Mask, out *bytes.Buffer) Decode(in *bytes.Reader, baseline S) (S, Mask, error) // Diff returns the mask of fields where state differs from baseline. Diff(state, baseline S) Mask }
Encoder writes a delta of `state` against `baseline` filtered by `mask` into out. Implementations are user-provided per state type.
type Ring ¶
type Ring[S any] struct { // contains filtered or unexported fields }
Ring is a fixed-size circular buffer of state snapshots keyed by frame number. Used by lag compensation for "what did entity look like N frames ago?" queries.
func NewRing ¶
NewRing returns a Ring sized to `size` entries. Push wraps around once the buffer is full.
func (*Ring[S]) At ¶
At returns the snapshot recorded at the given frame, if present and not overwritten by a later frame in the same slot.
type Tracker ¶
type Tracker[S any] struct { // contains filtered or unexported fields }
Tracker holds per-consumer baselines + reusable encode buffers and emits per-consumer deltas with zero allocations on the steady-state path (the buffer grows once to fit the max delta then is reused).
func NewTracker ¶
NewTracker constructs a Tracker.
func (*Tracker[S]) Ack ¶
Ack records that the consumer has acknowledged a frame. This is a caller-controlled hook; in a strict net-LOD protocol the baseline only advances on Ack, not on Append. The simple Tracker here advances on Append; consumers needing strict Ack-only advancement should add a frame-keyed history layer.
func (*Tracker[S]) Append ¶
Append computes the delta for consumerID and returns the encoded bytes from a per-consumer reusable buffer. The returned slice is valid until the next Append for the same consumerID — callers that need to retain the bytes across calls must copy them.
The current state becomes the new pending baseline; call Ack(consumerID, frame) to commit it.