Documentation
¶
Overview ¶
Package wire contains the compact, versioned on-the-wire format used by cascache to store values in the underlying Provider. It provides zero-copy decoders and pre-sized encoders for both single entries and bulk entries.
Encoding choices:
- All integers are big-endian (network byte order).
- A 4-byte ASCII magic ("CASC") allows quick format discrimination.
- A 1-byte version enables forward/backward compatibility in place.
- "kind" distinguishes single vs bulk payloads.
- The payload after the fixed header is codec-opaque ([]byte).
- Decoders are written for bounds safety: every slice operation is preceded by length checks; on any mismatch they return ErrCorrupt.
- Decoders return subslices of the original buffer for payloads (zero-copy).
- Encode paths pre-compute capacity and bytes.Buffer.Grow to avoid realloc.
- Bulk decode allocates exactly one string per item to materialize the key (stable map key semantics).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCorrupt is returned when a byte slice doesn't conform to the expected // structure (bad magic/version/kind/lengths). ErrCorrupt = errors.New("cascache: corrupt entry") )
Functions ¶
func DecodeSingle ¶
DecodeSingle parses a single entry and returns (gen, payload). The returned payload is a subslice of b (zero-copy).
func EncodeBulk ¶
EncodeBulk encodes a bulk set of items in a single value.
Layout (big-endian):
magic(4) | ver(1) | kind(1=bulk) | n(u32) repeated n times: keyLen(u16) | key(keyLen) | gen(u64) | vlen(u32) | payload(vlen)
Notes:
- keyLen must be in (0, 0xFFFF]; invalid lengths panic because this indicates a programmer error at the call site (not untrusted input).
func EncodeSingle ¶
EncodeSingle encodes a single entry.
Layout (big-endian):
magic(4) | ver(1) | kind(1=single) | gen(u64) | vlen(u32) | payload(vlen)
The payload is the codec-encoded value. gen is the per-key generation used for read-side validation (CAS).
Types ¶
type BulkItem ¶
BulkItem holds one member of a bulk-encoded set. Key is materialized as a Go string (one allocation) for stable map key use.
func DecodeBulk ¶
DecodeBulk parses a bulk entry into a slice of items.
For each item, Payload is a zero-copy subslice of b. Key is converted to a string (one allocation per item).