value

package
v0.0.0-...-599cc13 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearField

func ClearField(s *segment.Struct, fieldNum uint16, ft field.Type)

ClearField clears a field by setting it to its zero value.

func GetValue

func GetValue(s *segment.Struct, fieldNum uint16) interfaces.Value

GetValue allows us to get a Value from the internal Struct representation. If the value of the field is not set, GetValue() returns nil.

func RealStruct

func RealStruct(s interfaces.Struct) *segment.Struct

RealStruct extracts the *segment.Struct that holds all the data (not a reflect.Struct).

func SetField

func SetField(s *segment.Struct, fieldNum uint16, ft field.Type, v any)

SetField sets a field value using the segment setters.

func XXXNewStruct

func XXXNewStruct(v *segment.Struct, descr interfaces.StructDescr) interfaces.Struct

XXXNewStruct wraps our internal *segment.Struct objects in the reflect.Struct type. This is used in our generated code to implement the ClawStruct() method.

Types

type FieldDescrImpl

type FieldDescrImpl struct {
	FD *mapping.FieldDescr
	SD interfaces.StructDescr
	EG interfaces.EnumGroup
}

FieldDescrImpl describes a field inside a Struct type.

func (FieldDescrImpl) EnumGroup

func (f FieldDescrImpl) EnumGroup() interfaces.EnumGroup

EnumGroup returns the EnumGroup for the field. If the field is not an enum, this will panic. Use IsEnum() if you want to check before calling this.

func (FieldDescrImpl) FieldNum

func (f FieldDescrImpl) FieldNum() uint16

FieldNum returns the field number in the Struct.

func (FieldDescrImpl) IsEnum

func (f FieldDescrImpl) IsEnum() bool

IsEnum indicates if the field is an enumerator.

func (FieldDescrImpl) IsMap

func (f FieldDescrImpl) IsMap() bool

IsMap returns true if this field is a map type.

func (FieldDescrImpl) ItemType

func (f FieldDescrImpl) ItemType() string

ItemType returns the Struct type in a []Struct. If this is not a []Struct, then this will panic.

func (FieldDescrImpl) MapKeyType

func (f FieldDescrImpl) MapKeyType() field.Type

MapKeyType returns the key type for map fields.

func (FieldDescrImpl) MapValueType

func (f FieldDescrImpl) MapValueType() field.Type

MapValueType returns the value type for map fields.

func (FieldDescrImpl) Name

func (f FieldDescrImpl) Name() string

Name returns the name of the field.

func (FieldDescrImpl) Type

func (f FieldDescrImpl) Type() field.Type

Type returns the type of the field.

type ItemType

type ItemType struct {
	Name    string
	Path    string
	Mapping mapping.Map
}

type ListBools

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

func NewListBools

func NewListBools(items []bool) ListBools

func (ListBools) Append

func (l ListBools) Append(v interfaces.Value)

func (ListBools) Get

func (l ListBools) Get(i int) interfaces.Value

func (ListBools) Len

func (l ListBools) Len() int

func (ListBools) New

func (l ListBools) New() interfaces.Struct

func (ListBools) Set

func (l ListBools) Set(i int, v interfaces.Value)

func (ListBools) Type

func (l ListBools) Type() field.Type

type ListBytes

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

func NewListBytes

func NewListBytes(items [][]byte) ListBytes

func (ListBytes) Append

func (l ListBytes) Append(v interfaces.Value)

func (ListBytes) Get

func (l ListBytes) Get(i int) interfaces.Value

func (ListBytes) Len

func (l ListBytes) Len() int

func (ListBytes) New

func (l ListBytes) New() interfaces.Struct

func (ListBytes) Set

func (l ListBytes) Set(i int, v interfaces.Value)

func (ListBytes) Type

func (l ListBytes) Type() field.Type

type ListNumbers

type ListNumbers[N interfaces.Number] struct {
	// contains filtered or unexported fields
}

func NewListNumbers

func NewListNumbers[N interfaces.Number](items []N) ListNumbers[N]

func (ListNumbers[N]) Append

func (l ListNumbers[N]) Append(v interfaces.Value)

func (ListNumbers[N]) Get

func (l ListNumbers[N]) Get(i int) interfaces.Value

func (ListNumbers[N]) Len

func (l ListNumbers[N]) Len() int

func (ListNumbers[N]) New

func (l ListNumbers[N]) New() interfaces.Struct

func (ListNumbers[N]) Set

func (l ListNumbers[N]) Set(i int, v interfaces.Value)

func (ListNumbers[N]) Type

func (l ListNumbers[N]) Type() field.Type

type ListStrings

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

func NewListStrings

func NewListStrings(items []string) ListStrings

func (ListStrings) Append

func (l ListStrings) Append(v interfaces.Value)

func (ListStrings) Get

func (l ListStrings) Get(i int) interfaces.Value

func (ListStrings) Len

func (l ListStrings) Len() int

func (ListStrings) New

func (l ListStrings) New() interfaces.Struct

func (ListStrings) Set

func (l ListStrings) Set(i int, v interfaces.Value)

func (ListStrings) Type

func (l ListStrings) Type() field.Type

type ListStructs

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

func NewListStructs

func NewListStructs(items []*segment.Struct, m *mapping.Map) ListStructs

func (ListStructs) Append

func (l ListStructs) Append(v interfaces.Value)

func (ListStructs) Get

func (l ListStructs) Get(i int) interfaces.Value

func (ListStructs) Len

func (l ListStructs) Len() int

func (ListStructs) New

func (l ListStructs) New() interfaces.Struct

func (ListStructs) Set

func (l ListStructs) Set(i int, v interfaces.Value)

func (ListStructs) Type

func (l ListStructs) Type() field.Type

type MapImpl

type MapImpl[K segment.MapKey, V any] struct {
	// contains filtered or unexported fields
}

MapImpl is a generic map implementation that wraps segment.Maps. It provides a type-erased interface for reflection access to maps.

func NewMapImpl

func NewMapImpl[K segment.MapKey, V any](m *segment.Maps[K, V], keyType, valType field.Type, valDescr *StructDescrImpl) MapImpl[K, V]

NewMapImpl creates a new MapImpl wrapping a segment.Maps.

func (MapImpl[K, V]) Delete

func (m MapImpl[K, V]) Delete(key interfaces.Value)

func (MapImpl[K, V]) Get

func (m MapImpl[K, V]) Get(key interfaces.Value) interfaces.Value

func (MapImpl[K, V]) Has

func (m MapImpl[K, V]) Has(key interfaces.Value) bool

func (MapImpl[K, V]) KeyType

func (m MapImpl[K, V]) KeyType() field.Type

func (MapImpl[K, V]) Len

func (m MapImpl[K, V]) Len() int

func (MapImpl[K, V]) Range

func (m MapImpl[K, V]) Range(f func(key, val interfaces.Value) bool)

func (MapImpl[K, V]) Set

func (m MapImpl[K, V]) Set(key interfaces.Value, val interfaces.Value)

func (MapImpl[K, V]) ValueType

func (m MapImpl[K, V]) ValueType() field.Type

type PackageDescrImpl

type PackageDescrImpl struct {
	Name             string
	Path             string
	ImportDescrs     []interfaces.PackageDescr
	EnumGroupsDescrs interfaces.EnumGroups
	StructsDescrs    interfaces.StructDescrs
	// contains filtered or unexported fields
}

PackageDescrImpl is the implementation of PackageDescr.

func (*PackageDescrImpl) Enums

Enums is a list of the Enum declarations.

func (*PackageDescrImpl) FullPath

func (p *PackageDescrImpl) FullPath() string

FullPath returns the full path of the package.

func (*PackageDescrImpl) Imports

func (p *PackageDescrImpl) Imports() []interfaces.PackageDescr

Imports is a list of imported claw files.

func (*PackageDescrImpl) PackageName

func (p *PackageDescrImpl) PackageName() string

PackageName returns the name of the package.

func (*PackageDescrImpl) Structs

Messages is a list of the top-level message declarations.

type StructDescrImpl

type StructDescrImpl struct {
	Name      string
	Pkg       string
	Path      string
	FieldList []interfaces.FieldDescr

	Mapping *mapping.Map
	// contains filtered or unexported fields
}

StructDescrImpl implements StructDescr.

func (StructDescrImpl) FieldDescrByIndex

func (s StructDescrImpl) FieldDescrByIndex(index int) interfaces.FieldDescr

FieldDescByIndex returns the FieldDescr by index. If the index is out of bounds this will panic.

func (StructDescrImpl) FieldDescrByName

func (s StructDescrImpl) FieldDescrByName(name string) interfaces.FieldDescr

FieldDescrByName returns the FieldDescr by the name of the field. If the field is not found, this will be nil.

func (StructDescrImpl) Fields

func (s StructDescrImpl) Fields() []interfaces.FieldDescr

Fields will return a list of field descriptions.

func (StructDescrImpl) FullPath

func (s StructDescrImpl) FullPath() string

FullPath will return the full path of the package as used in Go import statements.

func (StructDescrImpl) New

New creates a new interfaces.Struct based on this StructDescrImpl.

func (StructDescrImpl) Package

func (s StructDescrImpl) Package() string

Package will be return name package name this struct was defined in.

func (StructDescrImpl) StructName

func (s StructDescrImpl) StructName() string

Struct Name will be the name of the struct.

type StructDescrsImpl

type StructDescrsImpl struct {
	Descrs []interfaces.StructDescr
	// contains filtered or unexported fields
}

StructDescrsImpl implements interfaces.StructDescrs. This stores a list of Struct inside a package.

func (StructDescrsImpl) ByName

ByName returns the StructDescr for a Struct named s. It returns nil if not found.

func (StructDescrsImpl) Get

Get returns the ith StructDescr. It panics if out of bounds.

func (StructDescrsImpl) Len

func (s StructDescrsImpl) Len() int

Len reports the number of messages.

type StructImpl

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

func NewStruct

func NewStruct(s *segment.Struct, descr interfaces.StructDescr) StructImpl

func (StructImpl) ClawInternal

func (s StructImpl) ClawInternal(pragma.DoNotImplement)

func (StructImpl) Clear

func (s StructImpl) Clear(desc interfaces.FieldDescr)

func (StructImpl) Descriptor

func (s StructImpl) Descriptor() interfaces.StructDescr

func (StructImpl) Fields

Fields returns an iterator over all field descriptors and values in the struct.

func (StructImpl) Get

func (StructImpl) Has

func (s StructImpl) Has(descr interfaces.FieldDescr) bool

func (StructImpl) New

func (s StructImpl) New() interfaces.Struct

func (StructImpl) NewField

func (s StructImpl) NewField(descr interfaces.FieldDescr) interfaces.Value

func (StructImpl) Range

Range iterates over fields using a callback function (legacy method). Consider using Fields() for better composability with Go 1.24 iterators.

func (StructImpl) Set

func (StructImpl) Struct

func (s StructImpl) Struct() *segment.Struct

Struct extracts the *segment.Struct that holds all the data (not a reflect.Struct).

type Value

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

Value represents a read-only Claw value. This can be used to retrieve a value or set a value.

func ValueOfBool

func ValueOfBool(v bool) Value

ValueOfBool returns a Value that represents bool.

func ValueOfBytes

func ValueOfBytes(v []byte) Value

ValueOfBytes returns a Value that represents []byte. Can be nil.

func ValueOfEnum

func ValueOfEnum[N ~uint8 | ~uint16](v N, enumGroup interfaces.EnumGroup) Value

ValueOfEnum returns a Value that represents an enumerator.

func ValueOfList

func ValueOfList(v interfaces.List) Value

ValueOfList returns a Value that represents List.

func ValueOfMap

func ValueOfMap(v interfaces.Map) Value

ValueOfMap returns a Value that represents a Map.

func ValueOfNumber

func ValueOfNumber[N interfaces.Number](v N) Value

ValueOfNumber returns a Value representing a number type.

func ValueOfString

func ValueOfString(v string) Value

ValueOfString returns a Value that represents a string.

func ValueOfStruct

func ValueOfStruct(v interfaces.Struct) Value

ValueOfStruct returns a Value that represents a Struct.

func (Value) Any

func (v Value) Any() any

Any decodes the value into the any type. If the value isn't valid, this panics. Here are a list of the decodes:

  • Enumerators will decode into the interfaces.Enum type
  • Bool will decode to the bool type
  • Numbers(int*, uint*, float*) decode into their Go equivalent
  • String into the string type
  • Bytes into the []byte type
  • Struct into reflect.Struct
  • List of bools into []bool
  • List of Numbers into []<go number type>
  • List of String into []string
  • List of Bytes into [][]byte
  • List of Struct into a []reflect.Struct

func (Value) Bool

func (v Value) Bool() bool

Bool returns the boolean value stored in Value. If Value is not a bool type, this will panic.

func (Value) Bytes

func (v Value) Bytes() []byte

Bytes returns the Bytes value stored in Value. If Value is not a Bytes type, this will panic.

func (Value) Enum

func (v Value) Enum() interfaces.Enum

Enum returns the enumerated value stored in Value. If Value is not an Enum type, this will panic.

func (Value) Float

func (v Value) Float() float64

Float returns the Float value stored in Value. If Value is not a Float type, this will panic.

func (Value) Int

func (v Value) Int() int64

Int returns the integer value stored in Value. If Value is not an integer type, this will panic.

func (Value) List

func (v Value) List() interfaces.List

List returns the List value stored in Value. If Value is not some list type, this will panic.

func (Value) Map

func (v Value) Map() interfaces.Map

Map returns the Map value stored in Value. If Value is not a map type, this will panic.

func (Value) String

func (v Value) String() string

String returns the string value stored in Value. String returns the string v's underlying value, as a string. String is a special case because of Go's String method convention. Unlike the other getters, it does not panic if v's Kind is not String. Instead, it returns a string of the form "<T value>" where T is v's type. The fmt package treats Values specially. It does not call their String method implicitly but instead prints the concrete values they hold.

func (Value) Struct

func (v Value) Struct() interfaces.Struct

Struct returns the Struct value stored in Value. If Value is not a Struct type, this will panic.

func (Value) Uint

func (v Value) Uint() uint64

Uint returns the unsigned integer value stored in Value. If Value is not an unsigned integer type, this will panic.

Jump to

Keyboard shortcuts

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