Documentation
¶
Overview ¶
Package encoding provides canonical, bounded binary frames for CRDT state.
Index ¶
- Constants
- Variables
- func AppendTag(dst []byte, tag crdt.Tag) []byte
- func AppendUvarint(dst []byte, value uint64) []byte
- func MarshalFrame(frame Frame) ([]byte, error)
- func MarshalFrameWithPayload(typeID uint64, codecID string, payloadLength int, writePayload PayloadWriter) ([]byte, error)
- func ReadBytes(data []byte, position, max int) ([]byte, int, bool)
- func ReadTag(data []byte, position, maxStringBytes int) (crdt.Tag, int, bool)
- func ReadUvarint(data []byte, position int) (uint64, int, bool)
- func TagSize(tag crdt.Tag) int
- func UvarintSize(value uint64) int
- type DecoderLimits
- type Frame
- type Limits
- type PayloadWriter
Constants ¶
const FormatVersion uint64 = 1
FormatVersion identifies the canonical frame layout implemented by this package. Unknown versions are rejected rather than guessed.
Variables ¶
var ( ErrInvalidFrame = errors.New("encoding: invalid frame") ErrFrameLimit = errors.New("encoding: frame limit exceeded") )
Functions ¶
func AppendUvarint ¶
AppendUvarint appends the unique shortest representation of value.
func MarshalFrame ¶
MarshalFrame returns the canonical v1 encoding of frame.
func MarshalFrameWithPayload ¶
func MarshalFrameWithPayload(typeID uint64, codecID string, payloadLength int, writePayload PayloadWriter) ([]byte, error)
MarshalFrameWithPayload returns the canonical v1 frame for a payload written directly into its final output buffer. When writePayload follows the PayloadWriter buffer-lifetime contract, this function owns the envelope and computes a checksum matching the completed payload.
func ReadBytes ¶
ReadBytes reads a length-prefixed byte sequence without allocating. max is an explicit bound for the sequence and must be non-negative.
func ReadTag ¶
ReadTag decodes one bounded canonical tag without retaining data's backing storage. The caller owns the returned tag value.
func ReadUvarint ¶
ReadUvarint reads one shortest-form unsigned varint at position. It rejects truncated, overflowing, and non-canonical encodings.
func UvarintSize ¶
UvarintSize returns the size of value's canonical unsigned-varint encoding.
Types ¶
type DecoderLimits ¶
type DecoderLimits struct {
MaxFrameBytes int
MaxPayload int
MaxCodecID int
MaxElements int
MaxTags int
MaxStringBytes int
}
DecoderLimits bounds decoder allocation and input work. All limits must be positive. MaxElements and MaxTags apply to a single decoded payload.
func DefaultLimits ¶
func DefaultLimits() DecoderLimits
DefaultLimits returns conservative bounds for in-memory library use. It returns a value rather than exposing mutable process-wide configuration.
type PayloadWriter ¶
PayloadWriter writes exactly one framed payload into the supplied buffer. The buffer has the requested payload length and is only valid for the duration of the call. Writers must not retain or modify it after returning.