Documentation
¶
Index ¶
- Constants
- func NoEscape(p unsafe.Pointer) unsafe.Pointer
- type ArrayType
- type EmptyInterface
- type Name
- type NameOff
- type PtrType
- type SliceType
- type StructField
- type StructTag
- type StructType
- type TFlag
- type Type
- func (t *Type) ArrayType() *ArrayType
- func (t *Type) Elem() *Type
- func (t *Type) Field(i int) (StructField, error)
- func (t *Type) IfaceIndir() bool
- func (t *Type) Kind() Kind
- func (t *Type) Name() string
- func (t *Type) NameByIndex(i int) (string, error)
- func (t *Type) NumField() (int, error)
- func (t *Type) PtrType() *PtrType
- func (t *Type) SliceType() *SliceType
- func (t *Type) String() string
- func (t *Type) StructID() uint32
- func (t *Type) StructType() *StructType
- type TypeOff
- type Value
- func (v Value) Addr() (Value, error)
- func (v Value) Bool() (bool, error)
- func (v Value) CanAddr() bool
- func (v Value) Cap() (int, error)
- func (v Value) Elem() (Value, error)
- func (v Value) Field(i int) (Value, error)
- func (v Value) Float() (float64, error)
- func (v Value) Index(i int) (Value, error)
- func (v Value) Int() (int64, error)
- func (v Value) Interface() (i any, err error)
- func (v Value) IsNil() (bool, error)
- func (v Value) Kind() Kind
- func (v Value) Len() (int, error)
- func (v Value) NumField() (int, error)
- func (v Value) Set(x Value) error
- func (v Value) SetBool(x bool) error
- func (v Value) SetBytes(x []byte) error
- func (v Value) SetFloat(x float64) error
- func (v Value) SetInt(x int64) error
- func (v Value) SetString(x string) error
- func (v Value) SetUint(x uint64) error
- func (v Value) String() string
- func (v Value) Type() *Type
- func (v Value) Uint() (uint64, error)
Constants ¶
const ( KindDirectIface Kind = 1 << 5 KindMask Kind = (1 << 5) - 1 )
Essential constants for type operations
Variables ¶
This section is empty.
Functions ¶
func NoEscape ¶ added in v0.0.13
NoEscape hides the pointer p from escape analysis, preventing it from escaping to the heap. It compiles down to nothing.
WARNING: This is very subtle to use correctly. The caller must ensure that it's truly safe for p to not escape to the heap by maintaining runtime pointer invariants (for example, that globals and the heap may not generally point into a stack).
Types ¶
type ArrayType ¶ added in v0.0.32
type ArrayType struct {
Type
Elem *Type // array element type
Slice *Type // slice type
Len uintptr // array length
}
ArrayType represents an array type.
type EmptyInterface ¶ added in v0.0.13
EmptyInterface describes the layout of a "interface{}" or a "any."
type Name ¶ added in v0.0.13
type Name struct {
Bytes *byte
}
func (Name) DataChecked ¶ added in v0.0.13
DataChecked does pointer arithmetic on n's Bytes, and that arithmetic is asserted to be safe for the reason in whySafe (which can appear in a backtrace, etc.)
func (Name) IsEmbedded ¶ added in v0.0.13
IsEmbedded returns true iff n is embedded (an anonymous field).
func (Name) IsExported ¶ added in v0.0.13
IsExported reports whether the name is exported.
func (Name) ReadVarint ¶ added in v0.0.13
ReadVarint parses a varint as encoded by encoding/binary. It returns the number of encoded bytes and the encoded value.
type NameOff ¶ added in v0.0.13
type NameOff int32
NameOff is the Offset to a Name from moduledata.types. See resolveNameOff in runtime.
type StructField ¶ added in v0.0.13
type StructField struct {
Name Name // name is always non-empty
Typ *Type // type of field
Off uintptr // offset within struct, in bytes
}
A StructField describes a single field in a struct.
func (*StructField) Embedded ¶ added in v0.0.13
func (f *StructField) Embedded() bool
func (StructField) Tag ¶ added in v0.0.13
func (f StructField) Tag() StructTag
Tag returns the field's tag as a StructTag.
type StructTag ¶ added in v0.0.13
type StructTag string
StructTag is the tag string in a struct field (similar to reflect.StructTag)
type StructType ¶ added in v0.0.13
type StructType struct {
Type
PkgPath Name
Fields []StructField
}
type TFlag ¶ added in v0.0.13
type TFlag uint8
TFlag is used by a Type to signal what extra type information is available in the memory directly following the Type value.
type Type ¶ added in v0.0.13
type Type struct {
Size uintptr
PtrBytes uintptr // number of (prefix) bytes in the type that can contain pointers
Hash uint32 // Hash of type; avoids computation in Hash tables
TFlag TFlag // extra type information flags
Align_ uint8 // alignment of variable with this type
FieldAlign_ uint8 // alignment of struct field with this type
Kind_ Kind // enumeration for C
// function for comparing objects of this type
Equal func(unsafe.Pointer, unsafe.Pointer) bool
// GCData stores the GC type data for the garbage collector.
// Normally, GCData points to a bitmask that describes the
// ptr/nonptr Fields of the type. The bitmask will have at
// least PtrBytes/ptrSize bits.
// If the TFlagGCMaskOnDemand bit is set, GCData is instead a
// **byte and the pointer to the bitmask is one dereference away.
// The runtime will build the bitmask if needed.
// (See runtime/type.go:getGCMask.)
// Note: multiple types may have the same value of GCData,
// including when TFlagGCMaskOnDemand is set. The types will, of course,
// have the same pointer layout (but not necessarily the same size).
GCData *byte
Str NameOff // string form
PtrToThis TypeOff // type for pointer to this type, may be zero
}
func TypeOf ¶ added in v0.0.13
TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.
func (*Type) ArrayType ¶ added in v0.0.32
ArrayType returns t cast to a *ArrayType, or nil if its tag does not match.
func (*Type) Elem ¶ added in v0.0.32
Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.
func (*Type) Field ¶ added in v0.0.13
func (t *Type) Field(i int) (StructField, error)
Field returns the i'th field of the struct type. It returns an error if the type is not a struct or the index is out of range.
func (*Type) IfaceIndir ¶ added in v0.0.13
IfaceIndir reports whether t is stored indirectly in an interface value.
func (*Type) Name ¶ added in v0.0.16
Name returns the type's name within its package for a defined type. For TinyGo compatibility, struct names are resolved using the StructDictionary
func (*Type) NameByIndex ¶ added in v0.0.19
Name returns the name of a struct type's i'th field. It panics if the type's Kind is not Struct. It panics if i is out of range.
func (*Type) NumField ¶ added in v0.0.13
NumField returns the number of fields in the struct type. It returns an error if the type is not a struct.
func (*Type) PtrType ¶ added in v0.0.32
PtrType returns t cast to a *PtrType, or nil if its tag does not match.
func (*Type) SliceType ¶ added in v0.0.32
SliceType returns t cast to a *SliceType, or nil if its tag does not match.
func (*Type) StructID ¶ added in v0.0.16
StructID returns a unique identifier for struct types based on runtime hash Returns 0 for non-struct types
func (*Type) StructType ¶ added in v0.0.13
func (t *Type) StructType() *StructType
StructType returns t cast to a *StructType, or nil if its tag does not match.
type TypeOff ¶ added in v0.0.13
type TypeOff int32
TypeOff is the Offset to a type from moduledata.types. See resolveTypeOff in runtime.
type Value ¶ added in v0.0.13
type Value struct {
// contains filtered or unexported fields
}
func Indirect ¶ added in v0.0.32
Indirect returns the value that v points to. If v is a nil pointer, Indirect returns a zero Value. If v is not a pointer, Indirect returns v.
func MakeSlice ¶ added in v0.0.32
MakeSlice creates a new zero-initialized slice value for the specified slice type, length, and capacity. Implementation adapted from /usr/local/go/src/reflect/value.go:2904
func New ¶
New returns a Value representing a pointer to a new zero value for the specified type. That is, the returned Value's Type is PtrTo(typ).
func ValueOf ¶ added in v0.0.13
ValueOf returns a new Value initialized to the concrete value stored in the interface i. ValueOf(nil) returns the zero Value.
func Zero ¶ added in v0.0.32
Zero returns a Value representing the zero value for the specified type.
func (Value) Addr ¶ added in v0.0.32
Addr returns a pointer value representing the address of v. It returns an error if CanAddr would return false.
func (Value) Bool ¶ added in v0.0.32
Bool returns v's underlying value. It returns an error if v's Kind is not Bool.
func (Value) CanAddr ¶ added in v0.0.32
CanAddr reports whether the value's address can be obtained with Value.Addr. Such values are called addressable. A value is addressable if it is an element of a slice, an element of an addressable array, a field of an addressable struct, or the result of dereferencing a pointer. If CanAddr returns false, calling Value.Addr will panic.
func (Value) Cap ¶ added in v0.0.32
Cap returns v's capacity. It returns an error if v's Kind is not Array, Chan, Slice or pointer to Array.
func (Value) Elem ¶ added in v0.0.17
Elem returns the value that the pointer v points to. It panics if v's Kind is not Ptr. It returns the zero Value if v is a nil pointer.
func (Value) Field ¶ added in v0.0.13
Field returns the i'th field of the struct v. Returns an error if v is not a struct or i is out of range.
func (Value) Float ¶ added in v0.0.32
Float returns v's underlying value, as a float64. It returns an error if v's Kind is not Float32 or Float64.
func (Value) Index ¶ added in v0.0.32
Index returns v's i'th element. It returns an error if v's Kind is not Array, Slice, or String or i is out of range.
func (Value) Int ¶ added in v0.0.32
Int returns v's underlying value, as an int64. It returns an error if v's Kind is not Int, Int8, Int16, Int32, or Int64.
func (Value) Interface ¶ added in v0.0.19
Interface returns v's current value as an interface{}. It is equivalent to:
var i interface{} = (v's underlying value)
For a Value created from a nil interface value, Interface returns nil.
func (Value) IsNil ¶ added in v0.0.32
IsNil reports whether its argument v is nil. It returns an error if v's Kind is not Chan, Func, Interface, Map, Pointer, or Slice.
func (Value) Kind ¶ added in v0.0.32
func (v Value) Kind() Kind
Kind returns the specific kind of this value.
func (Value) Len ¶ added in v0.0.32
Len returns v's length. It returns an error if v's Kind is not Array, Chan, Map, Slice, or String.
func (Value) Set ¶ added in v0.0.32
Set assigns x to the value v. It returns an error if CanSet would return false.
func (Value) SetBool ¶ added in v0.0.32
SetBool sets the bool value to the field represented by Value.
func (Value) SetBytes ¶ added in v0.0.32
SetBytes sets the byte slice value to the field represented by Value.
func (Value) SetFloat ¶ added in v0.0.32
SetFloat sets the float value to the field represented by Value.
func (Value) SetString ¶ added in v0.0.17
SetString sets the string value to the field represented by Value. It uses unsafe to write the value to the memory location of the field.
func (Value) SetUint ¶ added in v0.0.32
SetUint sets the uint value to the field represented by Value.
func (Value) String ¶ added in v0.0.32
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.