tpack

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 5 Imported by: 2

README

tpack

Go underlying type data.

  • import it

    "github.com/andeya/goutil/tpack"
    
  • doc

    // U go underlying type data
    type U struct {
        // Has unexported fields.
    }
    
    // Unpack unpacks i to go underlying type data.
    func Unpack(i interface{}) U
    
    // From gets go underlying type data from reflect.Value.
    func From(v reflect.Value) U
    
    // RuntimeTypeID gets the underlying type ID in current runtime from reflect.Type.
    // NOTE:
    //  *A and A gets the same runtime type ID;
    //  It is 10 times performance of t.String().
    func RuntimeTypeID(t reflect.Type) int32
    
    // RuntimeTypeID gets the underlying type ID in current runtime.
    // NOTE:
    //  *A and A gets the same runtime type ID;
    //  It is 10 times performance of reflect.TypeOf(i).String().
    func (u U) RuntimeTypeID() int32
    
    // Kind gets the reflect.Kind fastly.
    func (u U) Kind() reflect.Kind
    
    // Elem returns the U that the interface i contains
    // or that the pointer i points to.
    func (u U) Elem() U
    
    // UnderlyingElem returns the underlying U that the interface i contains
    // or that the pointer i points to.
    func (u U) UnderlyingElem() U
    
    // Pointer gets the pointer of i.
    // NOTE:
    //  *T and T, gets diffrent pointer
    func (u U) Pointer() uintptr
    
    // IsNil reports whether its argument i is nil.
    func (u U) IsNil() bool
    
    // FuncForPC returns a *Func describing the function that contains the
    // given program counter address, or else nil.
    //
    // If pc represents multiple functions because of inlining, it returns
    // the a *Func describing the innermost function, but with an entry
    // of the outermost function.
    //
    // NOTE: Its kind must be a reflect.Func, otherwise it returns nil
    func (u U) FuncForPC() *runtime.Func
    

Benchmark

goos: darwin
goarch: amd64
pkg: github.com/andeya/goutil/tpack
BenchmarkUnpack_tpack-4   	2000000000	         0.79 ns/op	       0 B/op	       0 allocs/op
BenchmarkTypeOf_go-4      	200000000	        10.3 ns/op	       0 B/op	       0 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RuntimeTypeID

func RuntimeTypeID(t reflect.Type) uintptr

RuntimeTypeID returns the underlying type ID in current runtime from reflect.Type. NOTE:

*A and A returns the different runtime type ID;
It is 10 times performance of t.String().

func RuntimeTypeIDOf added in v1.1.0

func RuntimeTypeIDOf(i interface{}) uintptr

RuntimeTypeIDOf returns the underlying type ID in current runtime from interface object. NOTE:

*A and A returns the different runtime type ID;
It is 10 times performance of t.String().

Types

type U

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

U go underlying type data

func From

func From(v reflect.Value) U

From gets go underlying type data from reflect.Value.

func From2 added in v1.1.0

func From2(v *reflect.Value) U

From2 gets go underlying type data from *reflect.Value.

func Unpack

func Unpack(i interface{}) U

Unpack unpacks i to go underlying type data.

func (U) CanAddr added in v1.1.0

func (v U) CanAddr() bool

CanAddr reports whether the value's address can be obtained with Addr. Such values are called addressable. A value is addressable if it is an element of a slice, an element of an addressable array, a field of an addressable struct, or the result of dereferencing a pointer.

func (U) Elem added in v1.1.0

func (v U) Elem() U

Elem returns the Value that the interface i contains or that the pointer i points to.

func (U) FuncForPC added in v1.1.0

func (v U) FuncForPC() *runtime.Func

FuncForPC returns a *Func describing the function that contains the given program counter address, or else nil.

If pc represents multiple functions because of inlining, it returns the a *Func describing the innermost function, but with an entry of the outermost function.

NOTE: Its kind must be a reflect.Func, otherwise it returns nil

func (U) IsNil added in v1.1.0

func (v U) IsNil() bool

IsNil reports whether its argument i is nil.

func (U) Kind added in v1.1.0

func (v U) Kind() reflect.Kind

Kind gets the reflect.Kind fastly.

func (U) Pointer added in v1.1.0

func (v U) Pointer() uintptr

Pointer gets the pointer of i. NOTE:

*T and T, gets diffrent pointer

func (U) RuntimeTypeID added in v1.1.0

func (v U) RuntimeTypeID() uintptr

RuntimeTypeID gets the underlying type ID in current runtime. NOTE:

*A and A gets the different runtime type ID;
It is 10 times performance of reflect.TypeOf(i).String().

func (U) UnderlyingElem added in v1.1.0

func (v U) UnderlyingElem() U

UnderlyingElem returns the underlying Value that the interface i contains or that the pointer i points to.

Jump to

Keyboard shortcuts

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