reflect

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeStructAnyEface

func ComposeStructAnyEface(val interface{}, rawType reflect.Type) interface{}

装配Any.Any的空接口表示

func CreateAnyStructOnElemType

func CreateAnyStructOnElemType(val interface{}) interface{}

CreateAnyStructOnElemType 通过数组/切片的元素类型 创建Any字段类型为[]val.Type的struct 返回的是其结构体的指针类型

func CreateAnyStructOnType

func CreateAnyStructOnType(val interface{}) interface{}

CreateAnyStructOnType 通过val的类型 创建Any字段类型为val.Type的struct,返回值类型为结构体的指针

func DeepEqualNotType

func DeepEqualNotType(x, y interface{}) bool

DeepEqualNotType 主要用于比较

func FuncInputTypeList

func FuncInputTypeList(value reflect.Value, start int, isRecv bool, directNew func(i int) bool) []interface{}

FuncInputTypeList 返回函数的输入参数类型列表,空接口切片表示 directNew是一个过滤器回调函数, 返回true指示new的类型是其原始类型, 返回false则代表new一个非指针类型并返回其指针 directNew()其入参的index当(isRecv == true), 它的值相当于减去接收器的参数的长度

Example
if directNew() == true { Input(*reflect.Value) Exec -> return new(*reflect.Value)}
if directNew() == false { Input(*reflect.Value) Exec -> tmp := new(reflect.Value) -> return &tmp}

func FuncOutputTypeList

func FuncOutputTypeList(value reflect.Value, directNew func(i int) bool) []interface{}

FuncOutputTypeList 返回函数的返回值类型列表,空接口切片表示 directNew是一个过滤器回调函数, 返回true指示new的类型是其原始类型, 返回false则代表new一个非指针类型并返回其指针 directNew()其入参的index当(isRecv == true), 它的值相当于减去接收器的参数的长度

Example
if directNew() == true { Input(*reflect.Value) Exec -> return new(*reflect.Value)}
if directNew() == false { Input(*reflect.Value) Exec -> tmp := new(reflect.Value) -> return &tmp}

func IdentArrayOrSliceType

func IdentArrayOrSliceType(value interface{}) interface{}

IdentArrayOrSliceType 识别数组/切片元素类型 type&data为nil则直接返回nil,有类型信息则新建再识别

func IdentifyTypeNoInfo

func IdentifyTypeNoInfo(value interface{}) (unsafe.Pointer, int)

IdentifyTypeNoInfo 无类型信息的识别,识别一些简单类型的长度并返回它们的指针 只支持32-64位长度的类型

func InterDataPointer

func InterDataPointer(val interface{}) unsafe.Pointer

InterDataPointer 获得val对应eface-data指针的值

func PtrDeriveValue

func PtrDeriveValue(ptrI interface{}, val interface{}) interface{}

PtrDeriveValue 根据ptrI提供的type,val提供的data派生一个eface 不会修改ptrI中的数据,因为只使用了reflect.TypeOf()获取type的指针 并没有使用ptrI中对应的efce的data的指针

func RealType

func RealType(value reflect.Value) reflect.Value

func SliceBackSpace

func SliceBackSpace(p interface{}, n uint) interface{}

func SliceIndex

func SliceIndex(p interface{}, n int) interface{}

SliceIndex 支持负数索引

func ToTypePtr

func ToTypePtr(v interface{}) (interface{}, bool)

ToTypePtr 将一个非指针的interface{}转换为他的指针底层表示 Bool表示是否非指针类型

func ToValueTypeEface

func ToValueTypeEface(val reflect.Value) interface{}

ToValueTypeEface 如果reflect.Value为nil则返回可以和nil比较的interface{}

Types

type Eface

type Eface struct {
	// contains filtered or unexported fields
}

type Iface

type Iface struct {
	// contains filtered or unexported fields
}

type SliceHeader

type SliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}

SliceHeader unsafe.Pointer使得编译器能够正确识别指针

Jump to

Keyboard shortcuts

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