info

package
v0.1.33 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package info contains toolset for lightweight reflection like actions for types

Index

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 BuildType

func BuildType(b io.Writer, pkg, name string, t *types.Struct, exported bool) (r int)

func Caster

func Caster[T any]() func(p uintptr) *T

func DeRefer

func DeRefer[T any](x *T) (v T)

func Empty

func Empty[T any]() (v 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 MakeSlice

func MakeSlice[T any](cl ...int) []T

MakeSlice with positive optional capacity and length

func Reader

func Reader[T, F any](offset int) (fn func(*T) F)

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 Refer

func Refer[T any](x T) (v *T)

func SizeOf

func SizeOf[T any]() uint

func SliceOf

func SliceOf[T any](x ...T) []T

func StringData

func StringData(v string) []byte

StringData unsafe.StringData in older than go v1.20

func ToString

func ToString(v []byte) string

func Writer

func Writer[T, K any](offset int) func(*T, K)

Types

type Accessor

type Accessor [2]any // [Getter:func(*T)K ,Setter:func(*T,K)]

func MakeAccessor

func MakeAccessor[T, F any](field Field) (a Accessor)

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

func MakeFactory[T any](typo Type) (f Factory)

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 Id

type Id string

type IdArray

type IdArray struct {
	Length  uint
	Element Identity
}

func (IdArray) Kind

func (i IdArray) Kind() Kind

func (IdArray) String

func (i IdArray) String() string

type IdBuiltIn

type IdBuiltIn string

func (IdBuiltIn) Kind

func (i IdBuiltIn) Kind() Kind

func (IdBuiltIn) String

func (i IdBuiltIn) String() string

type IdChan

type IdChan struct {
	Dir     int8 // 0: send and receive, positive: send, negative: receive
	Element Identity
}

func (IdChan) Kind

func (i IdChan) Kind() Kind

func (IdChan) String

func (i IdChan) String() string

type IdFunc

type IdFunc [2][]Identity

func (IdFunc) Kind

func (i IdFunc) Kind() Kind

func (IdFunc) String

func (i IdFunc) String() string

type IdMap

type IdMap [2]Identity

func (IdMap) Kind

func (i IdMap) Kind() Kind

func (IdMap) String

func (i IdMap) String() string

type IdPointer

type IdPointer [1]Identity

func (IdPointer) Kind

func (i IdPointer) Kind() Kind

func (IdPointer) String

func (i IdPointer) String() string

type IdSlice

type IdSlice [1]Identity

func (IdSlice) Kind

func (i IdSlice) Kind() Kind

func (IdSlice) String

func (i IdSlice) String() string

type IdType

type IdType [2]string

func (IdType) Kind

func (i IdType) Kind() Kind

func (IdType) String

func (i IdType) String() string

type Identity

type Identity interface {
	Kind() Kind
	fmt.Stringer
}

func ParseId

func ParseId(i Id) (r Identity)

type Kind

type Kind int
const (
	KindUnknown Kind = iota
	KindType
	KindSlice
	KindMap
	KindPointer
	KindFunc
	KindArray
	KindBuiltIn
	KindChan
)

type SliceUnsafeHeader

type SliceUnsafeHeader struct {
	Data *[0x7fff0000]byte
	Len  int
	Cap  int
}

type StringUnsafeHeader

type StringUnsafeHeader struct {
	Data *[0x7fff0000]byte
	Len  int
}

type Type

type Type struct {
	Name   string  //the type name
	Path   string  //the import path of type
	Fields []Field //the optional field
}

Type is the information of a type

Jump to

Keyboard shortcuts

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