reflecti

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	NoError           = "NoError"
	JsonError         = "JsonError"
	MethodNotFound    = "MethodNotFound"
	ParameterNotMatch = "ParameterNotMatch"
)

Variables

View Source
var (
	PtrOffset = func() uintptr {
		return unsafe.Offsetof(e.Word)
	}()
	KindOffset = func() uintptr {
		return unsafe.Offsetof(e.Typ.Kind)
	}()
	ElemOffset = func() uintptr {
		return unsafe.Offsetof(new(PtrType).Elem)
	}()
	SliceDataOffset = func() uintptr {
		return unsafe.Offsetof(new(reflect.SliceHeader).Data)
	}()
)

Functions

func ContainType

func ContainType()

TODO:

func CopyFieldValueByType

func CopyFieldValueByType(src any, sub any) bool

CopyFieldValueByType 根据类型复制字段 参数均为指针,sub类型为src field的类型

func CopyStruct

func CopyStruct(src any, dest any) error

Copy 复制结构体,浅表复制

func DereferenceInterfaceValue

func DereferenceInterfaceValue(v reflect.Value) reflect.Value

DereferenceInterfaceValue returns the value of the underlying type that implements the interface v.

func DereferencePtrValue

func DereferencePtrValue(v reflect.Value) reflect.Value

DereferencePtrValue returns the underlying non-pointer type value.

func DereferenceType

func DereferenceType(t reflect.Type) reflect.Type

func DereferenceValue

func DereferenceValue(v reflect.Value) reflect.Value

DereferenceValue dereference and unpack interface, get the underlying non-pointer and non-interface value.

func Hash

func Hash(v interface{}) uint32

func InvokeByValues

func InvokeByValues(method reflect.Value, params []reflect.Value) []any

func OriginalType

func OriginalType(typ reflect.Type) reflect.Type

获取引用类型的原始类型

func RuntimeTypeID

func RuntimeTypeID(t reflect.Type) uintptr

func SetField

func SetField(structValue reflect.Value, name string, value any) error

func SetField2

func SetField2(o interface{}, field string, v interface{})

func SetSubField

func SetSubField(src any, sub any) bool

SetSubField 设置字段值 参数均为指针,dst类型为src field的类型

func SetSubFieldValue

func SetSubFieldValue(srcValue reflect.Value, subValue reflect.Value) bool

SetSubFieldValue 设置字段值 subValue为srcValue field的类型

func TypeInfo

func TypeInfo(v interface{})

Types

type ChanType

type ChanType struct {
	Rtype
	Elem *Rtype  // channel element type
	Dir  uintptr // channel direction (ChanDir)
}

ChanType represents a channel type.

type Eface

type Eface struct {
	Type *Type
	Data unsafe.Pointer
}

type EmptyInterface

type EmptyInterface struct {
	Typ  *Rtype
	Word unsafe.Pointer
}

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 FuncID

type FuncID uint8

type Iface

type Iface struct {
	Itab *Itab
	Data unsafe.Pointer
}

type Imethod

type Imethod struct {
	Name NameOff // name of method
	Typ  TypeOff // .(*FuncType) underneath
}

imethod represents a method on an interface type

type InterfaceType

type InterfaceType struct {
	Rtype
	PkgPath Name      // import path
	Methods []Imethod // sorted by hash
}

interfaceType represents an interface type.

type Itab

type Itab struct {
	Inter  *InterfaceType
	Type   *Type
	Link   *Itab
	Hash   uint32 // copy of _type.hash. Used for type switches.
	Bad    bool   // type does not implement interface
	Inhash bool   // has this Itab been added to hash?
	Unused [2]byte
	Fun    [1]uintptr // variable sized
}

type MapType

type MapType struct {
	Rtype
	Key    *Rtype // map key type
	Elem   *Rtype // map element (value) type
	Bucket *Rtype // 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.

type Name

type Name struct {
	Bytes *byte
}

type NameOff

type NameOff int32 // offset to a name

type NonEmptyInterface

type NonEmptyInterface struct {
	// see ../runtime/iface.go:/Itab
	Itab *struct {
		Ityp *Rtype // static interface type
		Typ  *Rtype // dynamic concrete type
		Hash uint32 // copy of typ.hash

		Fun [100000]unsafe.Pointer // method table
		// contains filtered or unexported fields
	}
	Word unsafe.Pointer
}

NonEmptyInterface is the header for an interface value with methods.

type PtrType

type PtrType struct {
	Rtype
	Elem *Rtype // pointer element (pointed at) type
}

PtrType represents a pointer type.

type ReflectInvoker

type ReflectInvoker struct {
	Methods map[string]reflect.Value
}

func NewReflectInvoker

func NewReflectInvoker() *ReflectInvoker

func (*ReflectInvoker) InvokeByInterfaceArgs

func (r *ReflectInvoker) InvokeByInterfaceArgs(funcName string, Params []interface{}) []reflect.Value

func (*ReflectInvoker) InvokeByJson

func (r *ReflectInvoker) InvokeByJson(byteData []byte) []byte

func (*ReflectInvoker) InvokeByReflectArgs

func (r *ReflectInvoker) InvokeByReflectArgs(funcName string, par []reflect.Value) []reflect.Value

func (*ReflectInvoker) RegisterMethod

func (r *ReflectInvoker) RegisterMethod(v interface{})

type Request

type Request struct {
	FuncName string        `json:"funcName"`
	Params   []interface{} `json:"params"`
}

type Response

type Response struct {
	FuncName string        `json:"funcName"`
	Result   []interface{} `json:"result"`
	ErrorMsg string        `json:"errorMsg"`
}

type Rtype

type Rtype 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

	Align      uint8 // alignment of variable with this type
	FieldAlign uint8 // alignment of struct field with this type
	Kind       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    *byte   // garbage collection data
	Str       NameOff // string form
	PtrToThis TypeOff // type for pointer to this type, may be zero
	// contains filtered or unexported fields
}

Rtype must be kept in sync with ../runtime/type.go:/^type._type.

func RtypeOff

func RtypeOff(section unsafe.Pointer, off int32) *Rtype

type SliceType

type SliceType struct {
	Rtype
	Elem *Rtype // Slice element type
}

SliceType represents a Slice type.

type StructField

type StructField struct {
	Name        Name    // name is always non-empty
	Typ         *Rtype  // type of field
	OffsetEmbed uintptr // byte offset of field<<1 | isEmbedded
}

Struct field

type StructType

type StructType struct {
	Rtype
	PkgPath Name
	Fields  []StructField // sorted by offset
}

StructType represents a struct type.

type TextOff

type TextOff int32 // offset from top of text section

type Tflag

type Tflag uint8

type Type

type Type struct {
	Size       uintptr
	Ptrdata    uintptr // size of memory prefix holding all pointers
	Hash       uint32
	Tflag      Tflag
	Align      uint8
	FieldAlign uint8
	Kind       uint8
	// 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
	Str       NameOff
	PtrToThis TypeOff
}

type TypeOff

type TypeOff int32 // offset to an *Rtype

type Value

type Value struct {
	Typ *Rtype
	Ptr unsafe.Pointer
	Flag
}

func ConvertValue

func ConvertValue(v reflect.Value) Value

func ValueOf

func ValueOf(v interface{}) Value

func (Value) Kind

func (v Value) Kind() reflect.Kind

Kind gets the reflect.Kind fastly.

func (Value) Pointer

func (v Value) Pointer() uintptr

Pointer gets the pointer of i. NOTE:

*T and T, gets diffrent pointer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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