row2

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: 0BSD Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package row2 reads and writes the Fast2 and Compact2 KVO row formats. A Field or View borrows at most one byte span. The external schema supplies signedness and field meanings. Select the codec at the table boundary: these bytes cannot be decoded as Fast1 word-map data.

Index

Constants

View Source
const MaxBytes = 64 << 20
View Source
const MaxEntries = 1 << 20

Variables

View Source
var (
	ErrFormat = errors.New("row2: invalid row")
	ErrLayout = errors.New("row2: invalid layout")
	ErrKind   = errors.New("row2: wrong container kind")
	ErrType   = errors.New("row2: incompatible value")
	ErrOrder  = errors.New("row2: keys must be ordered and unique")
	ErrLimit  = errors.New("row2: container exceeds limit")
	ErrValue  = errors.New("row2: invalid input")
	ErrIndex  = errors.New("row2: index out of bounds")
)

Functions

func PayloadSize

func PayloadSize(v values.Value) uint64

PayloadSize bounds a scalar or immutable byte-span payload before encoding.

Types

type Editor

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

Editor holds a borrowed row until the first write. Snapshot freezes the current bytes, including for backends which retain a Put until commit. Use one editor by pointer. Do not copy an editor after its first write.

func Edit

func Edit(base View) *Editor

func (*Editor) Get

func (e *Editor) Get(path []Step, enc Encoding) values.Value

Get borrows from the current edit until the next Set. Snapshot the row before taking a view that must survive another write.

func (*Editor) Set

func (e *Editor) Set(path []Step, value values.Value, enc Encoding)

Set replaces a leaf. A scalar with an existing Fast cell changes eight bytes in owned storage. Changes in shape or Compact width stream through the writer; siblings, including unknown fields, retain their raw payloads.

func (*Editor) SetWithWriter

func (e *Editor) SetWithWriter(path []Step, value values.Value, enc Encoding, w *Writer)

SetWithWriter reuses metadata scratch across edits. The caller can share w across editors used sequentially. Each rebuilt row owns its output bytes.

func (*Editor) Snapshot

func (e *Editor) Snapshot() View

type Encoding

type Encoding uint8

Encoding specifies how a typed runtime value maps to row2 payload bytes. Strings and immutable byte spans share Data; Float32 uses the historical float64 wire encoding, while runtime values retain float32 bits.

const (
	Word Encoding = iota
	Signed
	Float32
	Data
	Timestamp
)

func (Encoding) String

func (e Encoding) String() string

type Field

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

Field is raw codec metadata, not a runtime value. Payloads borrow the source container; inline words retain their full width when copied without a model. Decode requires the schema's encoding. Copying unknown fields uses PutRaw.

func (Field) Container

func (v Field) Container() View

func (Field) Decode

func (v Field) Decode(enc Encoding) values.Value

func (Field) IsZero

func (v Field) IsZero() bool

func (Field) Payload

func (v Field) Payload() []byte

type Iterator

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

func (*Iterator) Next

func (it *Iterator) Next() (key uint64, text []byte, value Field, ok bool)

type KeyAccessOptions

type KeyAccessOptions uint8

KeyAccessOptions controls property access independently of the field ID.

const (
	// Compact selects compact storage when creating a child.
	Compact KeyAccessOptions = 1 << iota
	// Present preserves explicit zero values and present, empty children.
	Present
)

type Kind

type Kind int

Kind identifies a row2 container. Its values are part of the wire format.

const (
	Object     Kind = 0
	Dictionary Kind = 1
	List       Kind = 2
)

func (Kind) String

func (k Kind) String() string

type Layout

type Layout uint8

Layout selects the physical row2 container layout. The values match the low trailer bit: Compact2 is zero and Fast2 is one. They are not EDB's StorageFormat IDs, which also include other codecs.

const (
	Compact2 Layout = 0
	Fast2    Layout = 1
)

func (Layout) String

func (l Layout) String() string

type Step

type Step struct {
	Key     uint64
	Options KeyAccessOptions
}

Step names a schema property and its access options.

type View

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

View borrows one encoded container. Raw and child spans are read-only.

func Empty

func Empty(layout Layout) View

func Open

func Open(raw []byte) View

Open panics on error. Use TryOpen to handle errors explicitly.

func Trusted

func Trusted(b []byte) View

Trusted borrows bytes produced by the codec or validated at ingestion. The bytes and any borrowed children must outlive the view.

func TryOpen

func TryOpen(raw []byte) (v View, err error)

TryOpen validates a single bounded container. Spans are opaque; for untrusted input, open a modeled child separately before trusting its contents.

func (View) At

func (v View) At(index int, enc Encoding) values.Value

func (View) Child

func (v View) Child(s Step) View

Child returns a missing view for an absent field. A presence-significant field can represent a present, empty object using an explicit zero.

func (View) Get

func (v View) Get(key uint64, enc Encoding) values.Value

Get decodes one property using its declared encoding; it does not decode a row.

func (View) GetFast

func (v View) GetFast(key uint64) values.Value

GetFast borrows a field from Fast2, whose words and spans already have the runtime layout. The caller must ensure Indexed() and handle Float32 fields through Get(key, Float32), since those retain float64 bits on disk.

func (View) GetString

func (v View) GetString(key string, enc Encoding) values.Value

func (View) Has

func (v View) Has(key uint64) bool

func (View) HasString

func (v View) HasString(key string) bool

HasString distinguishes a missing dictionary entry from a present zero value.

func (View) Iter

func (v View) Iter() Iterator

func (View) Kind

func (v View) Kind() Kind

func (View) Layout

func (v View) Layout() Layout

Layout returns Compact2 for a missing view; use Missing to test presence.

func (View) Len

func (v View) Len() int

func (View) Missing

func (v View) Missing() bool

func (View) Raw

func (v View) Raw() []byte

func (View) RawAt

func (v View) RawAt(i int) Field

func (View) RawField

func (v View) RawField(key uint64) Field

func (View) RawString

func (v View) RawString(key string) Field

RawString looks up a raw dictionary entry. A missing key returns the zero value.

type Writer

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

Writer streams nested containers into one destination. Keys within an object or dictionary must arrive in strictly increasing order.

func AcquireWriter

func AcquireWriter(dst []byte) *Writer

AcquireWriter returns a writer with reusable directory scratch. dst and the encoded bytes belong to the caller, including after Release.

func (*Writer) Begin

func (w *Writer) Begin(key uint64, text string, kind Kind, layout Layout)

func (*Writer) BytesWritten

func (w *Writer) BytesWritten() []byte

func (*Writer) Count

func (w *Writer) Count() int

Count reports entries emitted in the currently open container.

func (*Writer) End

func (w *Writer) End()

func (*Writer) Finish

func (w *Writer) Finish(keepEmpty bool)

Finish closes a container, optionally preserving an explicitly empty child.

func (*Writer) Put

func (w *Writer) Put(key uint64, text string, v values.Value, enc Encoding)

func (*Writer) PutPresent

func (w *Writer) PutPresent(key uint64, text string, v values.Value, enc Encoding)

func (*Writer) PutRaw

func (w *Writer) PutRaw(key uint64, text string, v Field)

PutRaw preserves an unknown field's representation, including explicit zero.

func (*Writer) Release

func (w *Writer) Release()

Release an acquired writer exactly once. It returns directory scratch to the pool. Discard unusually large workspaces so one wide or deeply nested row cannot pin them between writes.

func (*Writer) ReserveEntries

func (w *Writer) ReserveEntries(n int)

ReserveEntries is optional capacity advice, not a count or framing promise. A source slice/model can supply it without sizing or encoding any child.

func (*Writer) Reset

func (w *Writer) Reset(dst []byte)

Jump to

Keyboard shortcuts

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