Documentation ¶
Index ¶
- Constants
- Variables
- func CanCast(t1, t2 reflect.Type, strict bool) bool
- func CopyFieldValueByType(src any, sub any) bool
- func CopyStruct(src any, dest any) error
- func DerefType(typ reflect.Type) reflect.Type
- func DerefValue(v reflect.Value) reflect.Value
- func FuncAddr(f interface{}) unsafe.Pointer
- func GetFuncPC(fn interface{}) uintptr
- func GetSubField[T any](v any) *T
- func Hash(v any) uint32
- func InitPtr(v reflect.Value) reflect.Value
- func InitStruct(v reflect.Value)
- func RuntimeTypeID(t reflect.Type) uintptr
- func SetField(structValue reflect.Value, name string, value any) error
- func SetField2(o any, field string, v any)
- func SetSubField(src any, sub any) bool
- func SetSubFieldValue(srcValue reflect.Value, subValue reflect.Value) bool
- func TypeInfo(v interface{})
- type ArrayType
- type ChanType
- type Eface
- type Flag
- type Func
- type FuncID
- type FuncType
- type IMethod
- type Iface
- type InterfaceType
- type Itab
- type KindHandler
- type Map
- type MapIterator
- type MapType
- type NameOff
- type PtrType
- type Slice
- type SliceType
- type String
- type StructField
- type StructType
- type TextOff
- type Type
- type TypeOff
- type Value
- type ValueHandler
- type ValueRecursionHandler
Constants ¶
const ( F_direct = 1 << 5 F_kind_mask = (1 << 5) - 1 )
GoType.KindFlags const
Variables ¶
var ( PtrOffset = func() uintptr { return unsafe.Offsetof(e.Value) }() KindOffset = func() uintptr { return unsafe.Offsetof(e.Type.KindFlags) }() ElemOffset = func() uintptr { return unsafe.Offsetof(new(PtrType).Elem) }() SliceDataOffset = func() uintptr { return unsafe.Offsetof(new(reflect.SliceHeader).Data) }() )
Functions ¶
func CopyFieldValueByType ¶
CopyFieldValueByType 根据类型复制字段 参数均为指针,sub类型为src field的类型
func DerefValue ¶ added in v1.5.11
DereferenceValue dereference and unpack interface, get the underlying non-pointer and non-interface value.
func GetSubField ¶ added in v1.5.11
func InitStruct ¶ added in v1.5.11
func RuntimeTypeID ¶
func SetSubField ¶
SetSubField 设置字段值 参数均为指针,dst类型为src field的类型
func SetSubFieldValue ¶
SetSubFieldValue 设置字段值 subValue为srcValue field的类型
Types ¶
type ArrayType ¶ added in v1.5.11
type ArrayType struct { Type Elem *Type // array element type Slice *Type // Slice type Len uintptr }
ArrayType represents a fixed array type.
type ChanType ¶
type ChanType struct { Type Elem *Type // channel element type Dir uintptr // channel direction (ChanDir) }
ChanType represents a channel type.
type Eface ¶
func UnpackEface ¶ added in v1.5.11
func UnpackEface(v interface{}) Eface
type Flag ¶
type Flag uintptr
const ( FlagKindWidth = 5 // there are 27 kinds FlagKindMask Flag = 1<<FlagKindWidth - 1 FlagStickyRO Flag = 1 << 5 FlagEmbedRO Flag = 1 << 6 FlagIndir Flag = 1 << 7 FlagAddr Flag = 1 << 8 FlagMethod Flag = 1 << 9 FlagMethodShift = 10 FlagRO Flag = FlagStickyRO | FlagEmbedRO )
type Func ¶
type Func struct { Entry uintptr // start pc Nameoff int32 // function name Args int32 // in/out args size Deferreturn uint32 // offset of start of a deferreturn call instruction from entry, if any. Pcsp uint32 Pcfile uint32 Pcln uint32 Npcdata uint32 CuOffset uint32 // runtime.cutab offset of this function's CU FuncID FuncID // set for certain special runtime functions Nfuncdata uint8 // must be last // contains filtered or unexported fields }
type FuncType ¶ added in v1.5.11
type FuncType struct { Type InCount uint16 OutCount uint16 // top bit is set if last input parameter is ... }
FuncType represents a function type.
A *Rtype for each in and out parameter is stored in an array that directly follows the funcType (and possibly its uncommonType). So a function type with one method, one input, and one output is:
struct { funcType uncommonType [2]*Rtype // [0] is in, [1] is out }
type Iface ¶
func AssertI2I2 ¶ added in v1.5.11
func UnpackIface ¶ added in v1.5.11
func UnpackIface(v interface{}) Iface
type InterfaceType ¶
interfaceType represents an interface type.
func IfaceType ¶ added in v1.5.11
func IfaceType(t *Type) *InterfaceType
type Itab ¶
type Itab struct { Inter *InterfaceType Type *Type Hash uint32 // copy of _type.hash. Used for type switches. Unused [4]byte Fun [1]uintptr // variable sized }
type KindHandler ¶ added in v1.5.11
type KindHandler [reflect.UnsafePointer + 1][]ValueRecursionHandler
func (*KindHandler) AddHandler ¶ added in v1.5.11
func (k *KindHandler) AddHandler(kind reflect.Kind, v ValueRecursionHandler)
func (*KindHandler) FillFloat ¶ added in v1.5.11
func (k *KindHandler) FillFloat(v ValueRecursionHandler)
func (*KindHandler) FillInt ¶ added in v1.5.11
func (k *KindHandler) FillInt(v ValueRecursionHandler)
func (*KindHandler) FillUint ¶ added in v1.5.11
func (k *KindHandler) FillUint(v ValueRecursionHandler)
func (*KindHandler) Handle ¶ added in v1.5.11
func (k *KindHandler) Handle(value reflect.Value)
type MapIterator ¶ added in v1.5.11
type MapType ¶
type MapType struct { Type Key *Type // map key type Elem *Type // map element (value) type Bucket *Type // internal bucket structure // function for hashing keys (ptr to key, seed) -> hash Hasher func(unsafe.Pointer, uintptr) uintptr KeySize uint8 // size of key slot ValueSize uint8 // size of value slot BucketSize uint16 // size of bucket Flags uint32 }
MapType represents a map type.
func (*MapType) IndirectElem ¶ added in v1.5.11
type StructField ¶
type StructField struct { Name *byte // name is always non-empty Typ *Type // type of field OffsetEmbed uintptr // byte offset of field<<1 | isEmbedded }
Struct field
type StructType ¶
type StructType struct { Type PkgPath *byte Fields []StructField // sorted by offset }
StructType represents a struct type.
type Type ¶
type Type struct { Size uintptr Ptrdata uintptr // number of bytes in the type that can contain pointers Hash uint32 // hash of type; avoids computation in hash tables Flags uint8 // extra type information flags Align uint8 // alignment of variable with this type FieldAlign uint8 // alignment of struct field with this type KindFlags uint8 // enumeration for C // function for comparing objects of this type // (ptr to object A, ptr to object B) -> ==? Equal func(unsafe.Pointer, unsafe.Pointer) bool // gcdata stores the GC type data for the garbage collector. // If the KindGCProg bit is set in kind, gcdata is a GC program. // Otherwise it is a ptrmask bitmap. See mbitmap.go for details. Gcdata *byte // garbage collection data Str NameOff // string form PtrToThis TypeOff // type for pointer to this type, may be zero }
Type must be kept in sync with ../runtime/type.go:/^type._type.
func UnpackType ¶ added in v1.5.11
type Value ¶
func ConvertValue ¶
type ValueHandler ¶ added in v1.5.11
type ValueRecursionHandler ¶ added in v1.5.11
type ValueRecursionHandler func(reflect.Value, ValueHandler)