Documentation
¶
Overview ¶
Package nativebind selects native bindings once, when a schema is built.
Index ¶
- func GenerateFields(w io.Writer, name, typ string, fields []FieldSpec)
- func Layout(t reflect.Type, fields *Struct, direct bool) *values.NativeLayout
- func Load(t reflect.Type, p unsafe.Pointer) values.Value
- func LoadSlot(t reflect.Type, p unsafe.Pointer) values.Value
- func Store(t reflect.Type, p unsafe.Pointer, v values.Value)
- func StoreSlot(t reflect.Type, p unsafe.Pointer, x values.Value)
- type Field
- type FieldSpec
- type GeneratedField
- type GeneratedFields
- type Mode
- type Struct
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateFields ¶
GenerateFields emits native operations using direct, typed Go expressions. Callers supply imports for nativebind, values, reflect, unsafe and field types. Both evmbind and record generators use this emitter.
func Layout ¶
Layout describes native memory for a reflected or generated field binding. The operations are also used for native addresses retained by EVM.
func Load ¶
Load reads a native value for a host result. Map values carry the map identity and slice values retain their backing array and bounds.
func LoadSlot ¶
LoadSlot and StoreSlot are the shared reflection fallback for native storage. The supplied pointer addresses a Go value of exactly t, never VM cell storage.
Types ¶
type Field ¶
type Field struct {
Name string
Type reflect.Type
Offset uintptr
Get func(unsafe.Pointer) values.Value
Set func(unsafe.Pointer, values.Value)
}
Field accesses a field of a live Go struct. The owner pointer must refer to the registered Go type and remain alive for the operation. Structs, arrays, maps and slices are borrowed by address; pointers retain their native target. Scalar and string values use the ordinary values.Value representation.
type FieldSpec ¶
FieldSpec describes one exported native Go field to the shared generator. Type is its Go source spelling in the generated file's import environment.
type GeneratedField ¶
type GeneratedField struct {
Name string
Get func(unsafe.Pointer) values.Value
Set func(unsafe.Pointer, values.Value)
}
GeneratedField supplies generated access operations for a native field.
type GeneratedFields ¶
type GeneratedFields struct {
Type reflect.Type
New func() unsafe.Pointer
Fields []GeneratedField
}
GeneratedFields is emitted alongside evmbind wrappers or KVO codecs. Type and the complete exposed field list are checked once during registration.
type Mode ¶
type Mode uint8
Mode controls whether native operations may fall back when generated bindings are missing or stale.
Automatic permits fallback. StaticOnly requires compatible generated bindings.
type Struct ¶
type Struct struct {
Type reflect.Type
Fields []Field
New func() unsafe.Pointer
Generated bool
// contains filtered or unexported fields
}
Struct is an immutable native field binding. It is independent of KVO property numbers, VM memory layouts and the lifetime of any one object.
func BindFields ¶
func BindFields(t reflect.Type, generated *GeneratedFields, mode Mode) *Struct
BindFields prepares access to the struct fields of t using the specified binding mode.
Example ¶
package main
import (
"fmt"
"reflect"
"unsafe"
"github.com/andreyvit/evm/nativebind"
"github.com/andreyvit/evm/values"
)
func main() {
type Order struct{ Total int64 }
binding := nativebind.BindFields(reflect.TypeFor[Order](), nil, nativebind.Automatic)
total := binding.Field("Total")
order := Order{Total: 5}
fmt.Println(total.Get(unsafe.Pointer(&order)).AsInt())
total.Set(unsafe.Pointer(&order), values.Int(7))
fmt.Println(order.Total)
}
Output: 5 7
func BindSelectedFields ¶
func BindSelectedFields(t reflect.Type, names []string, generated *GeneratedFields, mode Mode) *Struct
BindSelectedFields binds a subset without changing native field offsets. A nil selection includes every exported field; an empty slice exposes none.