Documentation ¶
Overview ¶
Package info contains toolset for lightweight reflection like actions for types
Index ¶
- Variables
- func AssignRefer[T any](v T, x *T) *T
- func BuildType(b io.Writer, pkg, name string, t *types.Struct, exported bool) (r int)
- func Caster[T any]() func(p uintptr) *T
- func DeRefer[T any](x *T) (v T)
- func Empty[T any]() (v T)
- func EmptyRefer[T any]() *T
- func MakeMap[K comparable, T any](size ...int) (m map[K]T)
- func MakeSlice[T any](cl ...int) []T
- func Reader[T, F any](offset int) (fn func(*T) F)
- func Refer[T any](x T) (v *T)
- func SizeOf[T any]() uint
- func SliceOf[T any](x ...T) []T
- func StringData(v string) []byte
- func ToString(v []byte) string
- func Writer[T, K any](offset int) func(*T, K)
- type Accessor
- type Factory
- type Field
- type Id
- type IdArray
- type IdBuiltIn
- type IdChan
- type IdFunc
- type IdMap
- type IdPointer
- type IdSlice
- type IdType
- type Identity
- type Kind
- type SliceUnsafeHeader
- type StringUnsafeHeader
- type Type
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PointerSize = IntSize IntSize = BitSize / 8 BitSize = bits.UintSize )
View Source
var (
Sizes = types.SizesFor("gc", runtime.GOARCH)
)
Functions ¶
func AssignRefer ¶
func AssignRefer[T any](v T, x *T) *T
func EmptyRefer ¶
func EmptyRefer[T any]() *T
func MakeMap ¶
func MakeMap[K comparable, T any](size ...int) (m map[K]T)
MakeMap with positive optional size
func Reader ¶
Reader create read function at offset of struct with unsafe.
This should only use to assign to a global variable, It's not safe! ¶
examples:
1. read slice underlying:
//underlying slice is struct{ data *[size]T, len int,cap int } pointerReader := Reader[[]Some, uintptr](0) lenReader := Reader[[]Some, int](PointerSize) capReader := Reader[[]Some, int](PointerSize + IntSize)
2. read string underlying:
//underlying string is struct{ data []byte len int } dataReader := Reader[string, []byte](0) lenReader := Reader[string, int](PointerSize)
2. read first field
reader := Reader[Some, int](0)
func StringData ¶
StringData unsafe.StringData in older than go v1.20
Types ¶
type Accessor ¶
type Accessor [2]any // [Getter:func(*T)K ,Setter:func(*T,K)]
func MakeAccessor ¶
MakeAccessor see also [ReaderPointer] [WriterPointer]
type Factory ¶
type Factory struct { Type Empty any // the instance function of [Empty] Refer any // the instance function of [Refer] DeRefer any // the instance function of [DeRefer] SliceOf any // the instance function of [SliceOf] MakeSlice any // the instance function of [MakeSlice] Accessors []Accessor }
func MakeFactory ¶
MakeFactory without accessors, use MakeAccessor to create Accessors
type Field ¶
type Field struct { Name string //the field name Tag string //the field tag Id Id // the string present of type Embedded bool Offset int //the field offset from begin of struct Size int //the field size }
Field is the information of a field of type
type IdChan ¶
type SliceUnsafeHeader ¶
type StringUnsafeHeader ¶
Click to show internal directories.
Click to hide internal directories.