Documentation
¶
Overview ¶
Package dedup splits a JSON request body into a skeleton and content-addressed pieces, and rebuilds the exact bytes from them. Agent clients resend the whole conversation every turn, so storing each unique message, tool definition and system prompt once removes most of a payload store's volume.
Split works on raw bytes and never re-serialises JSON: a piece is the verbatim bytes of one array element (or one whole value), and the skeleton is the body with those bytes cut out. Rebuild must reproduce the input byte for byte; Split checks that itself and falls back to storing the body as a single piece when it cannot, so a caller never stores something it cannot read back.
The split rule knows no wire shape: every top-level array is split per element, every other top-level value of at least minValuePiece bytes is one piece, and the rest stays in the skeleton.
Out of scope: storage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMissingPiece = errors.New("dedup: missing piece")
ErrMissingPiece is returned by Rebuild when lookup has no piece for a hash.
Functions ¶
func CommonPrefix ¶
CommonPrefix returns how many leading hashes a and b share. For two requests of one conversation, the first differing index is where a prompt-cache prefix stops matching.
Types ¶
type Field ¶
type Field struct {
// Name is the top-level key, empty for a body stored whole.
Name string
// Array is true when the value was an array split per element; the
// pieces are rejoined with commas. Otherwise the value is one piece.
Array bool
// Offset is the byte position in the skeleton where the pieces go.
Offset int
// Hashes lists the field's pieces in order, repeats included.
Hashes []Hash
}
Field is where one top-level field's pieces go back into the skeleton.
type Hash ¶
type Hash [16]byte
Hash is the first 16 bytes of the SHA-256 of a piece's bytes. Pieces may be shared across owners, so the hash must resist construction: an accidental collision needs ~2^64 pieces, and corrupting another caller's piece needs a second preimage (~2^128 work).
type Piece ¶
Piece is one unique content-addressed fragment of a body. Body aliases the input passed to Split.
type Split ¶
type Split struct {
Skeleton []byte
// Fields are in ascending Offset order.
Fields []Field
// Pieces holds each distinct piece once, in first-seen order.
Pieces []Piece
}
Split is a body broken into a skeleton plus pieces.