values

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: 15 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.

README

Shared values

Package values defines the two-word runtime representation shared by EVM, KVO, and nativebind. Every runtime value travels as a Value:

type Value struct {
    R uint64
    P unsafe.Pointer
}

At the Go boundary, pack means to convert a Go value into an EVM value. Unpack means to convert it back to Go. values.Codec[T] pairs a Go Type with Pack func(T) Value (Go → EVM value) and Unpack func(Value) T (EVM value → Go); constructors such as SignedCodec, UnsignedCodec, BoolCodec, Float32Codec, Float64Codec, StringCodec, BytesCodec, and TimeCodec supply zero-allocation scalar codecs. A slot is a position holding a value. In the VM’s general storage layout, a cell is one addressable element of a []Value. A flattened struct may occupy several cells. The shape supplies the type and describes what each cell holds.

A Value does not carry its own type or presence bit—the operation that reads it supplies its Type, and presence is tracked separately. A Type defines nominal identity and how the value sits in registers (Raw, Pointer, or Pair). A Shape describes its storage layout.

GC invariant: P must always be a real GC-visible pointer or nil. Never hide pointers in R, and never store integer payloads in P.

Payloads

Each kind of value uses R and P according to its representation:

  • Integers: Decoded bits in R; narrow signed values are sign-extended.
  • Floats: IEEE-754 bits in R; float32 uses the low 32 bits.
  • Strings and immutable byte spans: Byte length in R, backing pointer in P. Borrowing allocates no wrapper, so the backing storage must stay valid and immutable for as long as the value is live.
  • Mutable slices: uint32 length and capacity packed in R, backing pointer in P. Copying the header preserves aliases to the same backing array.
  • Functions: Program-local reference index plus 1 in R (0 means nil). Closures keep their immutable capture cells in P, and mutable captured variables share cells.
  • Time: Unix nanoseconds (plus a reserved zero sentinel) when they fit in 64 bits; otherwise a 12-byte integer payload storing Unix seconds and nanoseconds. The instant immediately before the Unix epoch uses a shared payload to avoid colliding with the zero sentinel.
    • Time always stores an instant in UTC.
    • NativeTime preserves a complete Go time.Time: canonical UTC values use the compact encoding above, while values with a location or monotonic clock use an immutable 24-byte time.Time copy with R set to math.MaxUint64. AsTime restores the time zone and monotonic reading from this form, and ownership transfer shares the immutable copy.
    • Legacy string timestamps remain readable.
  • KVO records and collections: Compact TypedPair values carrying a physical representation ID.
Typed pairs

A TypedPair packs the 4-bit tag 0110, a 28-bit representation ID, and a 32-bit auxiliary value into R, with the payload pointer in P. For an encoded byte span, the auxiliary word holds the byte length.

Register immutable Shape metadata once at startup: representation IDs live for the lifetime of the process and are never reclaimed. Code operating on a concrete scalar type must never interpret arbitrary numeric bits as tags—the declared type always wins.

Interfaces

TypeTable packs and unpacks interface values with their exact dynamic types. Scalars use marker pointers in P so they can keep all 64 payload bits in R. Because a scalar's bits can match any bit prefix, always check marker pointers before interpreting R tags.

Only (R=0, P=nil) is a nil interface. Typed nils, false, and numeric zero are all non-nil interfaces. Always unpack with Unpack; P is not guaranteed to point to a heap box.

R prefix Remaining R payload
0000 60-bit concrete type ID; P is the direct pointer or a fallback box
0100 60-bit plain string length
10 / 11 32-bit length and 30-bit spare capacity for the selected []byte or []any type
0010 60-bit concrete type ID; P is a native Go pointer, including nil (pair pointer payload with R=NativeAddress)
0001 16-bit exact type ID and 44-bit string length
0011 16-bit exact type ID, 12-bit spare capacity, and 32-bit length
0101 16-bit exact type ID, 22-bit spare capacity, and 22-bit length
0110 28-bit representation ID and 32-bit auxiliary value

Implicit slice tags select exact linked types, and slice capacity is length + spare. Values that do not fit in these compact encodings fall back to a Value box; functions also box inside interfaces. Note that JSON maps and arrays still allocate their own backing storage even when their interface header needs no box.

Equality and hashing respect named types, Go comparability rules, NaN, and signed zero. Program-local type IDs and marker pointers belong to one linked program—never copy them into another program without repacking.

Aggregate storage

NewStructShape and NewPointerShape create nominal type identities. Build and reuse them during setup; the linker snapshots their graph.

  • VM structs and arrays live in flattened, GC-scanned cells. An extra trailing cell keeps addresses of trailing zero-sized fields inside the allocation.
  • Register aggregate values point to immutable snapshots; loads and stores copy aggregate cells, while pointer moves preserve aliases.
  • Shape.Stored returns a borrowed view—snapshot it before exposing it as an immutable value.
  • Shape.Store copies aggregate cells and clears unused scalar halves. Never mutate an aggregate snapshot.
  • Map keys and values must be snapshots, though any maps, slices, and pointers they reference keep their normal Go aliasing.

Shape helpers operate on VM cells, not arbitrary native Go pointers. For Go memory layouts and field operations, use nativebind (which KVO shares). Raw codec fields remain codec metadata until converted to a Value with their declared encoding.

See EVM and the KVO access guide.

Documentation

Overview

Package values defines two-word values shared by KVO adapters and EVM. Concrete types and presence are supplied separately; interface values encode their dynamic type using a program-local TypeTable.

Index

Constants

View Source
const NativeAddress uint64 = 1

NativeAddress marks a pointer into live Go memory. A pointer with R=0 refers to VM cells. The pointer's static type determines whether it carries this discriminator; opaque interface receivers continue to use their own ABI.

View Source
const NativeBorrow uint64 = ^uint64(0)

NativeBorrow marks an aggregate borrowed from a host. A typed VM boundary materializes it before assigning it to an aggregate register.

Variables

View Source
var (
	IntType     = NewType("int", Raw)
	UintType    = NewType("uint", Raw)
	UintptrType = NewType("uintptr", Raw)
	Int8        = NewType("int8", Raw)
	Int16       = NewType("int16", Raw)
	Int32       = NewType("int32", Raw)
	Uint8       = NewType("uint8", Raw)
	Uint16      = NewType("uint16", Raw)
	Uint32      = NewType("uint32", Raw)
	Float32Type = NewType("float32", Raw)
)
View Source
var (
	Int64      = NewType("i64", Raw)
	Uint64     = NewType("u64", Raw)
	Float64    = NewType("f64", Raw)
	Boolean    = NewType("bool", Raw)
	BoolType   = Boolean
	StringType = NewOwnedType("string", Pair, ownString)
	AnyType    = NewType("any", Pair)
	ErrorType  = NewType("error", Pair)
)
View Source
var ErrComparisonDepth = errors.New("value is nested too deeply to compare")

ComparisonError is a Go language panic condition, distinct from corrupt interface storage. EVM may recover it; invalid type indexes stay fatal. ErrComparisonDepth reports a value nested too deeply to compare or hash.

View Source
var TimeType = NewOwnedType("time.Time", Pair, func(v Value, b OwnershipBudget) (Value, error) {
	if v.P == nil || v.R == nativeTimeTag {
		return v, nil
	}
	if err := b.ChargeAllocation(v.R); err != nil {
		return Value{}, err
	}
	return Bytes(append([]byte(nil), v.AsBytes()...)), nil
})

Functions

func CellAt

func CellAt(p unsafe.Pointer, n uint64) unsafe.Pointer

func NativeTimeAllocBytes

func NativeTimeAllocBytes(t time.Time) uint64

NativeTimeAllocBytes reports the allocation made by NativeTime.

Types

type CellStruct

type CellStruct struct {
	// Untagged cells carry their logical type externally and box at any boundaries.
	Untagged    bool
	Type        *Type
	Get         func(Value, int) Value
	Pack        func([2]Value) Value
	LoadNative  func(unsafe.Pointer) Value
	StoreNative func(unsafe.Pointer, Value)
}

CellStruct preserves a two-field Go struct while storing value copies in one cell. Addressable values use their native layout; Get reads immutable cells. Descriptors are immutable setup metadata, not per-value objects.

func CompactOptional

func CompactOptional(name string, elem *Shape) *CellStruct

CompactOptional stores a Value/Present struct in one cell for numeric, boolean, string, and registered compact-struct payloads. Other payloads keep their ordinary struct representation. Markers belong to the descriptor, so no permanent representation IDs are used.

type Codec

type Codec[T any] struct {
	Type   reflect.Type
	Unpack func(Value) T
	Pack   func(T) Value
}

Codec packs Go values into EVM values and unpacks them back to Go. Its functions do not inspect runtime types. Type is declaration metadata, used only when binding a codec. Strings and bytes borrow their input storage in both directions.

func BoolCodec

func BoolCodec[T ~bool]() Codec[T]

func BytesCodec

func BytesCodec[T ~[]byte]() Codec[T]

func Float32Codec

func Float32Codec[T ~float32]() Codec[T]

func Float64Codec

func Float64Codec[T ~float64]() Codec[T]

func SignedCodec

func SignedCodec[T Signed]() Codec[T]

func StringCodec

func StringCodec[T ~string]() Codec[T]

func TimeCodec

func TimeCodec() Codec[time.Time]

func UnsignedCodec

func UnsignedCodec[T Unsigned]() Codec[T]

type ComparisonError

type ComparisonError struct {
	Type string
	Hash bool
	// contains filtered or unexported fields
}

func (*ComparisonError) Error

func (e *ComparisonError) Error() string

func (*ComparisonError) Unwrap

func (e *ComparisonError) Unwrap() error

type DynamicType

type DynamicType struct {
	Shape      *Shape
	Comparable bool
}

type Field

type Field struct {
	Embedded bool
	Tag      string
	Name     string
	Shape    *Shape
	Offset   uint64
}

type Kind

type Kind uint8
const (
	BoolKind Kind = iota + 1
	IntKind
	UintKind
	FloatKind
	StringKind
	PointerKind
	StructKind
	ArrayKind
	SliceKind
	MapKind
	ComplexKind
	FunctionKind
	InterfaceKind
	// TypedPairKind carries a registered physical layout and auxiliary word.
	TypedPairKind
	TimestampKind
	// NativeValueKind retains an opaque Go interface with native equality.
	NativeValueKind
)

type Map

type Map struct {
	Key   *Shape
	Types *TypeTable
	// contains filtered or unexported fields
}

Map stores immutable key/value snapshots. Mutable values inside them (pointers, maps and slices) retain Go aliasing. Deleted entries remain only in iterators.

func NewMap

func NewMap(key *Shape, ts *TypeTable) *Map

func (*Map) Clear

func (m *Map) Clear()

func (*Map) Delete

func (m *Map) Delete(k Value, h uint64) error

func (*Map) DeleteContext

func (m *Map) DeleteContext(ctx context.Context, k Value, h uint64) error

func (*Map) Entries

func (m *Map) Entries() []*MapEntry

Entries snapshots the existing iteration range; insertions may be skipped. Updates are observed and deleted entries are skipped by the iterator.

func (*Map) EntryCount

func (m *Map) EntryCount() uint64

func (*Map) Find

func (m *Map) Find(k Value, h uint64) (*MapEntry, bool, error)

func (*Map) FindContext

func (m *Map) FindContext(ctx context.Context, k Value, h uint64) (*MapEntry, bool, error)

func (*Map) Len

func (m *Map) Len() int

func (*Map) ProbeCount

func (m *Map) ProbeCount(hash uint64) uint64

func (*Map) Put

func (m *Map) Put(k, v Value, h uint64) error

func (*Map) PutContext

func (m *Map) PutContext(ctx context.Context, k, v Value, h uint64) error

type MapEntry

type MapEntry struct {
	Key, Value Value
	Live       bool
}

type Method

type Method struct {
	ID        string
	Signature *Shape
}

Method is a receiver-free interface requirement. ID includes the defining package path for unexported methods.

type NativeAddressCodec

type NativeAddressCodec struct {
	Encode func(unsafe.Pointer) Value
	Decode func(Value) (unsafe.Pointer, error)
}

NativeAddressCodec preserves a logical pointer representation for native storage.

type NativeCompare

type NativeCompare struct {
	Comparable bool
	Zero       unsafe.Pointer
	Steps      []NativeCompareStep
}

NativeCompare preserves Go field order when an opaque snapshot supplies fields omitted from the script layout. A nonnegative Field selects VM cells.

type NativeCompareStep

type NativeCompareStep struct {
	Field int
	Equal func(unsafe.Pointer, unsafe.Pointer) bool
	Hash  func(unsafe.Pointer) uint64
	Work  func(unsafe.Pointer, uint64) (uint64, bool)
}

type NativeField

type NativeField struct {
	// Layout records physical slot storage when it differs from the logical shape.
	Layout *NativeLayout
	// Cells marks VM cells embedded in synthetic aggregate storage.
	// Their addresses and values keep the ordinary guest representation.
	Cells  bool
	Offset uintptr
	Get    func(unsafe.Pointer) Value
	Set    func(unsafe.Pointer, Value)
}

type NativeLayout

type NativeLayout struct {
	Address *NativeAddressCodec
	Codec   *NativeValueCodec
	// OpaqueCell is the one-based cell holding an immutable native snapshot
	// for fields omitted from the script type. Zero means no snapshot.
	OpaqueCell uint64
	Compare    *NativeCompare
	GoType     reflect.Type
	Array      *NativeSliceLayout
	Map        *NativeMapLayout
	Slice      *NativeSliceLayout
	Size       uint64
	New        func() unsafe.Pointer
	Load       func(unsafe.Pointer) Value
	Store      func(unsafe.Pointer, Value)
	Fields     []NativeField
}

NativeLayout supplies operations on Go memory, independently of VM cells. Load returns decoded scalars/strings, native pointer targets, or a borrowed native aggregate address. VM aggregate conversion remains an explicit step.

type NativeMapIterator

type NativeMapIterator interface {
	Next(key, value unsafe.Pointer) bool
}

type NativeMapLayout

type NativeMapLayout struct {
	Key, Element *NativeLayout
	Load         func(unsafe.Pointer) Value
	Store        func(unsafe.Pointer, Value)
	Make         func() unsafe.Pointer
	Len          func(unsafe.Pointer) int
	Lookup       func(mapPtr, key, result unsafe.Pointer) bool
	Update       func(mapPtr, key, value unsafe.Pointer)
	Delete       func(mapPtr, key unsafe.Pointer)
	Clear        func(unsafe.Pointer)
	Iter         func(unsafe.Pointer) NativeMapIterator
}

NativeMapLayout operates on a Go map identity, not a field holding that map. Reassigning the source field therefore does not retarget existing aliases.

type NativeSliceLayout

type NativeSliceLayout struct {
	Element     *NativeLayout
	Array       func(uint64) *NativeLayout
	ElementSize uint64
	Load        func(unsafe.Pointer) Value
	Store       func(unsafe.Pointer, Value)
	Make        func(uint32) unsafe.Pointer
	Copy        func(dst, src unsafe.Pointer, count uint32)
	Clear       func(unsafe.Pointer, uint32)
}

NativeSliceLayout operates on Go slice storage. VM values retain the backing array pointer and Go length/capacity; element addresses use native byte strides. Copy and Clear must retain Go write barriers for pointer-bearing elements.

type NativeSliceView

type NativeSliceView struct {
	Data             unsafe.Pointer
	Layout           *NativeLayout
	Element          *NativeLayout
	Length, Capacity uint32
}

NativeSliceView carries physical storage per value. Linking a host slice declaration must not change the backing layout of ordinary guest slices. Length and Capacity retain the full uint32 range of ordinary slice headers.

type NativeValueCodec

type NativeValueCodec struct {
	Decode func(Value) (Value, error)
	Encode func(Value, func(uint64) error) (Value, error)
}

NativeValueCodec converts a native slot to its logical VM value. The encode callback charges any new native storage before allocating it.

type OwnFunc

type OwnFunc func(Value, OwnershipBudget) (Value, error)

OwnFunc discharges borrowed-storage dependencies while preserving the logical value. It may return already independent values unchanged. Mutable identity needs an explicit contract; a shallow copy is not generally sufficient.

type OwnershipBudget

type OwnershipBudget interface {
	ChargeAllocation(uint64) error
	ContextErr() error
}

OwnershipBudget is supplied at ownership boundaries, never on ordinary reads. ChargeAllocation must succeed before allocating a clone's backing storage.

type Repr

type Repr uint8
const (
	Raw     Repr = 1
	Pointer Repr = 2
	Pair         = Raw | Pointer
)

type RepresentationID

type RepresentationID uint32

RepresentationID identifies immutable physical-layout metadata. Several representations may share a logical Type. IDs are process-local, never reused, and must not be persisted or allocated per value or transaction.

func RegisterRepresentation

func RegisterRepresentation(shape *Shape) RepresentationID

RegisterRepresentation publishes a physical layout for a compact typed pair. The supplied shape and its reachable metadata must remain immutable.

func (RepresentationID) Shape

func (id RepresentationID) Shape() *Shape

type Shape

type Shape struct {
	CellStruct       *CellStruct
	Native           *NativeLayout // optional live Go representation, distinct from Cells
	NativeAllocation *NativeLayout // backing for newly allocated collections; does not change stored values
	// NativePointerType marks a typed-pair physical representation of a live Go
	// pointer. Representations of the same logical type and Go pointer type
	// compare by address, independently of their field-access plans.
	NativePointerType reflect.Type
	// DisplayName is optional source-language spelling, prepared at compile time.
	DisplayName string
	Methods     []Method

	Params, Results []*Shape
	// PointerLike gives opaque typed pairs pointer nil semantics: P == nil is
	// the zero value regardless of representation metadata. Other pairs may
	// legitimately carry nonzero auxiliary data with a nil pointer.
	PointerLike bool
	Variadic    bool
	Type        *Type
	Kind        Kind
	Bits        uint8
	Elem, Key   *Shape
	Fields      []Field
	Len         uint64
	Cells       uint64
}

Shape describes typed VM storage. Descriptors, including recursive graphs, are built before use and never mutated by execution. Link snapshots them. Scalar cells hold one Value. Structs/arrays flatten their members into cells; their register values point to immutable snapshots (nil means all zero).

func NewPointerShape

func NewPointerShape(elem *Shape) *Shape

NewPointerShape declares a pointer to VM cell storage. Reuse the result when declaring signatures and TypeDecls. Live native Go pointers instead use the NativeSchema produced by bindings, which supplies their native layout.

func NewStructShape

func NewStructShape(name string, fields ...Field) *Shape

NewStructShape declares a nominal VM struct using the same Shape and Field metadata as compiled structs. It copies the fields and computes cell offsets; supplied offsets are ignored. Child shapes must be fully laid out already. Build and retain shapes during setup. Type identity is by pointer, not name.

func (*Shape) Aggregate

func (s *Shape) Aggregate() bool

func (*Shape) Comparable

func (s *Shape) Comparable() bool

func (*Shape) Equal

func (s *Shape) Equal(a, b Value, ts *TypeTable) (bool, error)

func (*Shape) EqualContext

func (s *Shape) EqualContext(ctx context.Context, a, b Value, ts *TypeTable) (bool, error)

EqualContext allows cancellation during traversal of compound values.

func (*Shape) FieldValue

func (s *Shape) FieldValue(v Value, i int) Value

FieldValue reads a field of a value copy, including compact structs.

func (*Shape) GetField

func (s *Shape) GetField(p unsafe.Pointer, i int) Value

GetField borrows a field of VM cell storage. Aggregate fields point into that storage; use the field shape's Store to copy them. p must be nonnil storage for this struct shape, never a pointer to a native Go struct.

func (*Shape) Hash

func (s *Shape) Hash(v Value, ts *TypeTable) (uint64, error)

func (*Shape) HashContext

func (s *Shape) HashContext(ctx context.Context, v Value, ts *TypeTable) (uint64, error)

HashContext allows cancellation during traversal of compound values.

func (*Shape) LogicalKind

func (s *Shape) LogicalKind() Kind

LogicalKind hides a compact physical representation from reflection consumers.

func (*Shape) NativeStorage

func (s *Shape) NativeStorage() bool

NativeStorage reports whether this shape supports live native allocation. VM collection and interface layouts remain distinct from Go storage.

func (*Shape) New

func (s *Shape) New() unsafe.Pointer

New allocates zeroed VM cell storage for this shape, not a native Go object. The extra cell gives even a trailing zero-sized field an address in the allocation, matching VM allocations. All writes use Go write barriers.

func (*Shape) SetField

func (s *Shape) SetField(p unsafe.Pointer, i int, v Value)

SetField writes a field of VM cell storage. Scalar pointers alias their targets; aggregate fields copy their cells, using the same Store as the VM.

func (*Shape) Store

func (s *Shape) Store(p unsafe.Pointer, v Value)

func (*Shape) Stored

func (s *Shape) Stored(p unsafe.Pointer) Value

func (*Shape) Work

func (s *Shape) Work(v Value, limit uint64, ts *TypeTable) (uint64, bool)

Work bounds traversal of a value before hashing/comparison. It follows value fields only, never pointers; repeated string fields count each traversal.

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Type

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

Type is external metadata. Identity is by pointer, not by name.

func NewOwnedType

func NewOwnedType(name string, repr Repr, own OwnFunc) *Type

func NewType

func NewType(name string, repr Repr) *Type

func (*Type) CanOwn

func (t *Type) CanOwn() bool

func (*Type) Name

func (t *Type) Name() string

func (*Type) Own

func (t *Type) Own(v Value, b OwnershipBudget) (Value, error)

func (*Type) Repr

func (t *Type) Repr() Repr

type TypeTable

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

TypeTable owns the program-local identities and encoding of interface values. Entry zero is nil. The table and its descriptors are immutable after creation.

func NewTypeTable

func NewTypeTable(types []DynamicType) *TypeTable

func (*TypeTable) Comparable

func (ts *TypeTable) Comparable(id uint64) bool

func (*TypeTable) Index

func (ts *TypeTable) Index(v Value) uint64

Index extracts the dynamic type ID; Unpack validates the payload. Scalar markers must be checked first: their R contains all 64 bits.

func (*TypeTable) Inline

func (ts *TypeTable) Inline(id uint64, v Value) (Value, bool)

Inline packs a concrete payload without allocation. Callers box the payload when it does not fit. Aggregates must already be immutable snapshots.

func (*TypeTable) Unpack

func (ts *TypeTable) Unpack(v Value) (*Shape, Value, error)

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Value

type Value struct {
	R uint64
	P unsafe.Pointer
}

func Bool

func Bool(v bool) Value

func BorrowByteSlice

func BorrowByteSlice(data []byte, layout *NativeLayout, budget OwnershipBudget) (Value, error)

BorrowByteSlice exposes exactly len(data) bytes. Binding declarations must describe the result's borrow domain so the compiler can own escaping values.

func BorrowNative

func BorrowNative(typ reflect.Type, p unsafe.Pointer) Value

BorrowNative retains the Go type with its address until a host value is imported.

func Bytes

func Bytes(b []byte) Value

Bytes borrows an immutable byte span. R is its byte length, unlike a mutable VM slice whose header packs length and capacity. The external type distinguishes byte spans, strings and VM slices. The backing bytes must outlive this value.

func CellSlice

func CellSlice(p unsafe.Pointer, n uint64) []Value

func Float

func Float(v float64) Value

func Float32

func Float32(v float32) Value

func Int

func Int(v int64) Value

func NativeSliceValue

func NativeSliceValue(view *NativeSliceView) Value

NativeSliceValue retains a native view. Callers account for its allocation.

func NativeTime

func NativeTime(t time.Time) Value

NativeTime preserves Go value semantics. Canonical UTC values keep the compact timestamp encoding; all other values retain a full native copy.

func NativeValue

func NativeValue(x any) Value

NativeValue retains an opaque Go value. Callers must account for the allocated interface cell. The payload is immutable; snapshots share it without copying the underlying Go value or changing pointer identity.

func SliceValue

func SliceValue(p unsafe.Pointer, length, capacity uint32) Value

func String

func String(v string) Value

String retains the immutable string data without allocating a wrapper.

func Time

func Time(t time.Time) Value

Time stores nanoseconds in one word when they fit, with zero reserved for time.Time{}. Dates outside that range use a 12-byte integer payload (uint32 nanoseconds, int64 Unix seconds, big endian). No precision or date range is lost. Like database timestamps, the value denotes an instant, without a monotonic clock reading or timezone. AsTime returns UTC.

func TypedPair

func TypedPair(id RepresentationID, p unsafe.Pointer, aux uint32) Value

TypedPair keeps a real GC-visible pointer and a 32-bit auxiliary word in one cell. The ID must come from RegisterRepresentation. Auxiliary data commonly holds the length of an immutable byte span; it is not a second pointer.

func Uint

func Uint(v uint64) Value

func (Value) AsBool

func (v Value) AsBool() bool

func (Value) AsBytes

func (v Value) AsBytes() []byte

func (Value) AsFloat

func (v Value) AsFloat() float64

func (Value) AsFloat32

func (v Value) AsFloat32() float32

func (Value) AsInt

func (v Value) AsInt() int64

func (Value) AsNativeValue

func (v Value) AsNativeValue() any

AsNativeValue requires a NativeValueKind payload.

func (Value) AsString

func (v Value) AsString() string

AsString requires StringType. The data must remain valid and immutable.

func (Value) AsTime

func (v Value) AsTime() time.Time

func (Value) AsUint

func (v Value) AsUint() uint64

func (Value) Auxiliary

func (v Value) Auxiliary() uint32

func (Value) BorrowedNative

func (v Value) BorrowedNative() reflect.Value

BorrowedNative returns the typed pointer created by BorrowNative.

func (Value) HasNativeSlice

func (v Value) HasNativeSlice() bool

HasNativeSlice reports whether the value carries per-slice physical metadata.

func (Value) IsBorrowedByteView

func (v Value) IsBorrowedByteView() bool

func (Value) NativeComparable

func (v Value) NativeComparable() bool

NativeComparable reports Go type comparability. A comparable struct can still contain an interface holding an uncomparable value, just as in native Go.

func (Value) NativeSlice

func (v Value) NativeSlice() *NativeSliceView

NativeSlice returns a view suitable for exposing writable native memory.

func (Value) NativeTimeAddress

func (v Value) NativeTimeAddress() unsafe.Pointer

NativeTimeAddress returns the immutable native payload, or nil for compact instants. Callers may read or copy it, but must never mutate it.

func (Value) OwnBytes

func (v Value) OwnBytes() error

OwnBytes switches all aliases to one writable array. A failed reservation leaves every view attached to the original storage.

func (Value) ReadNativeSlice

func (v Value) ReadNativeSlice() *NativeSliceView

ReadNativeSlice resolves physical metadata for an immediate read. Its Data pointer is valid until an alias detaches.

func (Value) Representation

func (v Value) Representation() RepresentationID

Representation returns zero for an untagged value. Concrete scalar callers must not interpret arbitrary numeric bits as tags: their external type wins.

func (Value) SliceCap

func (v Value) SliceCap() uint32

func (Value) SliceData

func (v Value) SliceData() unsafe.Pointer

SliceData returns the writable element backing address.

func (Value) SliceLen

func (v Value) SliceLen() uint32

func (Value) SliceReadData

func (v Value) SliceReadData() unsafe.Pointer

SliceReadData returns a transient address for reads or nil tests.

func (Value) SliceView

func (v Value) SliceView(lo, length, capacity uint32, b OwnershipBudget) (Value, error)

SliceView creates a subview with the original physical layout. Borrowed offsets resolve against the shared backing on every access.

Jump to

Keyboard shortcuts

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