codec

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxMillis = 86_399_999
)

Variables

This section is empty.

Functions

func Decode added in v0.2.0

func Decode[T any](data []byte) (*T, error)

func Encode added in v0.2.0

func Encode[T any](value T) ([]byte, error)

func ValidateChunk added in v0.2.0

func ValidateChunk(chunk ChunkEntry) error

func ValidateCompact added in v0.2.0

func ValidateCompact(meta *CompactMetadata, day string) error

func ValidateManifest added in v0.2.0

func ValidateManifest(m *Manifest, day, writer string) error

Types

type ChunkEntry

type ChunkEntry struct {
	Sequence   Sequence         `json:"sequence"`
	Entries    uint32           `json:"entries"`
	Time       [2]uint32        `json:"time"`
	BitmapSize int64            `json:"bitmapSize"`
	Data       Range            `json:"data"`
	Size       int64            `json:"size"`
	ETag       string           `json:"etag"`
	Actors     map[uint32]Range `json:"actors,omitempty"`
}

ChunkEntry describes one immutable writer chunk.

func (ChunkEntry) Between

func (c ChunkEntry) Between(from, to uint32) bool

type Codec

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

Codec handles ZSTD compression and decompression operations.

func NewCodec

func NewCodec() (*Codec, error)

NewCodec creates a new codec with ZSTD encoder and decoder.

func (*Codec) Close

func (c *Codec) Close()

Close closes the encoder and decoder.

func (*Codec) Compress

func (c *Codec) Compress(data []byte) ([]byte, error)

Compress compresses data using ZSTD compression.

func (*Codec) Decompress

func (c *Codec) Decompress(compressed []byte) ([]byte, error)

Decompress decompresses ZSTD compressed data.

type CompactMetadata added in v0.2.0

type CompactMetadata struct {
	Day         string           `json:"day"`
	PublishedAt int64            `json:"publishedAt"`
	Index       ObjectRange      `json:"index"`
	Actors      map[uint32]Range `json:"actors"`
	Sources     []CompactSource  `json:"sources"`
}

type CompactSource added in v0.2.0

type CompactSource struct {
	Writer   string      `json:"writer"`
	Sequence Sequence    `json:"sequence"`
	Base     uint64      `json:"base"`
	Entries  uint32      `json:"entries"`
	Time     [2]uint32   `json:"time"`
	Payload  ObjectRange `json:"payload"`
	Source   string      `json:"source"`
	Copied   bool        `json:"copied"`
}

type CompressionError

type CompressionError struct {
	Operation string
	Err       error
}

CompressionError represents a compression/decompression error.

func (*CompressionError) Error

func (e *CompressionError) Error() string

func (*CompressionError) Unwrap

func (e *CompressionError) Unwrap() error

type Event added in v0.2.0

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

Event is a zero-copy view over a validated event frame. Returned slices are read-only by contract; Clone creates independent storage.

func NewEvent added in v0.2.0

func NewEvent(day time.Time, entry LogEntry) Event

func (Event) Actors added in v0.2.0

func (e Event) Actors() iter.Seq[uint32]

func (Event) Bytes added in v0.2.0

func (e Event) Bytes() []byte

func (Event) Clone added in v0.2.0

func (e Event) Clone() Event

func (Event) JSON added in v0.2.0

func (e Event) JSON() json.RawMessage

func (Event) Text added in v0.2.0

func (e Event) Text() string

func (Event) Time added in v0.2.0

func (e Event) Time() time.Time

type LogEntry

type LogEntry []byte

LogEntry is one validated on-disk event frame.

func NewLogEntry

func NewLogEntry(millis uint32, text string, actors []uint32) (LogEntry, error)

func ValidateEntries added in v0.2.0

func ValidateEntries(data []byte, expected uint32) ([]LogEntry, error)

ValidateEntries validates an entire decompressed chunk once at its boundary.

func ValidateEntry added in v0.2.0

func ValidateEntry(data []byte) (LogEntry, int, error)

ValidateEntry validates the first frame in data and returns its exact view.

func (LogEntry) Actors

func (e LogEntry) Actors() iter.Seq[uint32]

func (LogEntry) Millis added in v0.2.0

func (e LogEntry) Millis() uint32

type Manifest added in v0.2.0

type Manifest struct {
	Day    string       `json:"day"`
	Writer string       `json:"writer"`
	Chunks []ChunkEntry `json:"chunks"`
}

Manifest is the append-only index owned by one writer for one UTC day.

func (*Manifest) NextSequence added in v0.2.0

func (m *Manifest) NextSequence() uint64

type ObjectRange added in v0.2.0

type ObjectRange struct {
	Key    string `json:"key"`
	ETag   string `json:"etag"`
	Offset int64  `json:"offset"`
	Size   int64  `json:"size"`
}

type Range added in v0.2.0

type Range struct {
	Offset int64 `json:"offset"`
	Size   int64 `json:"size"`
}

Range locates immutable bytes within an object.

type Sequence added in v0.2.0

type Sequence uint64

Sequence is a writer-local chunk sequence encoded as 20 decimal digits.

func (Sequence) MarshalJSON added in v0.2.0

func (s Sequence) MarshalJSON() ([]byte, error)

func (*Sequence) UnmarshalJSON added in v0.2.0

func (s *Sequence) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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