store

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateAtIndex  = 0
	UpdateAtIndex  = 8
	MaxAgeIndex    = 16
	LengthIndex    = 24
	DataStartIndex = 32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store []byte

Store is a compact binary blob that prefixes the payload with metadata:

[0..7]   : createdAt (unix milli)
[8..15]  : updatedAt (unix milli)
[16..23] : maxAge (user-defined units)
[24..31] : payload length (bytes)
[32..]   : payload bytes

This format is intended for simple binary serialization of values.

func NewStore

func NewStore(data []byte, maxAge ...uint64) Store

NewStore builds a Store with the given payload and optional maxAge. maxAge is a metadata field and not interpreted by Store.

func ParseStore

func ParseStore(data []byte) Store

ParseStore validates the minimum length and returns a Store view over data. Returns an empty Store if the input is invalid.

func (Store) Bytes

func (s Store) Bytes() []byte

Bytes returns the payload bytes.

func (Store) CreateAt

func (s Store) CreateAt() uint64

CreateAt returns the creation timestamp (unix milli).

func (Store) Int

func (s Store) Int() (int, error)

Int interprets the payload as a big‑endian unsigned 64‑bit integer and returns it as int. Returns an error if the payload is too small.

func (Store) JSON

func (s Store) JSON(dest interface{}) error

JSON unmarshals the payload into dest.

func (Store) Length

func (s Store) Length(all ...bool) uint64

Length returns the payload length in bytes. If all=true, returns total store length.

func (Store) MaxAge

func (s Store) MaxAge() uint64

MaxAge returns the stored maxAge metadata value.

func (Store) SetLength

func (s Store) SetLength(length uint64) Store

SetLength updates the payload length and returns the mutated store.

func (Store) SetMaxAge

func (s Store) SetMaxAge(maxAge uint64) Store

SetMaxAge updates the stored maxAge and returns the mutated store.

func (Store) SetUpdateAt

func (s Store) SetUpdateAt(date uint64) Store

SetUpdateAt sets the last update timestamp and returns the mutated store.

func (Store) Text

func (s Store) Text() string

Text returns the payload as a string.

func (Store) UpdateAt

func (s Store) UpdateAt() uint64

UpdateAt returns the last update timestamp (unix milli).

func (Store) Values

func (s Store) Values() []byte

Values returns the raw underlying bytes, including metadata and payload.

Jump to

Keyboard shortcuts

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