delta

package
v1.0.36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package delta provides bounded batching and coalescing for encoded CRDT deltas. It does not choose a network transport or retry policy.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLimit        = errors.New("delta: batch limit exceeded")
	ErrInvalid      = errors.New("delta: invalid batch")
	ErrTypeMismatch = errors.New("delta: frame type mismatch")
	ErrMergeRetry   = errors.New("delta: merge retry limit exceeded")
)

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// contains filtered or unexported fields
}

Batch contains immutable copies of encoded delta frames.

func NewBatch

func NewBatch(items [][]byte, maxBytes int) (Batch, error)

NewBatch deep-copies items and rejects total payload over maxBytes.

func UnmarshalBatch

func UnmarshalBatch(data []byte, maxItems, maxBytes int) (Batch, error)

UnmarshalBatch accepts one complete canonical batch envelope and copies its items. maxItems and maxBytes bound both allocation and parsing work.

func (Batch) Items

func (b Batch) Items() [][]byte

Items returns deep copies of the encoded delta frames.

func (Batch) MarshalBinary

func (b Batch) MarshalBinary(maxBytes int) ([]byte, error)

MarshalBinary returns the canonical batch envelope. Individual items remain independent CRDT frames, so callers can diagnose or replay them separately.

type Coalescer

type Coalescer struct {
	// contains filtered or unexported fields
}

Coalescer stores a bounded stream of same-type encoded deltas. With merge set, Add replaces the tail with its join, avoiding a scan of earlier items. With nil merge it is a bounded FIFO batch builder.

func NewCoalescer

func NewCoalescer(maxItems, maxBytes int, merge MergeFunc) (*Coalescer, error)

NewCoalescer creates an empty bounded coalescer.

func (*Coalescer) Add

func (c *Coalescer) Add(item []byte) error

Add validates item as a CRDT frame and appends or joins it. On error the coalescer is unchanged.

func (*Coalescer) Drain

func (c *Coalescer) Drain() Batch

Drain returns the accumulated batch and resets c. The result owns its item bytes and can be safely retained by the caller.

func (*Coalescer) Len

func (c *Coalescer) Len() (items, bytes int)

Len reports the queued item count and total item bytes.

type MergeFunc

type MergeFunc func(left, right []byte) ([]byte, error)

MergeFunc joins two encoded deltas of the same type. It must return a valid canonical delta frame with the same type and codec ID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL