Documentation ¶
Index ¶
- func ArrayAt(p unsafe.Pointer, i int, elemSize uintptr) unsafe.Pointer
- func BytesToString(b []byte) string
- func CastInt(v interface{}) int64
- func CastIntPointer(kind reflect.Kind, ptr unsafe.Pointer) int64
- func IsIdenticalThriftType(a, b interface{}) (equal bool, diff string)
- func IsIdenticalType(a, b interface{}) (equal bool, diff string)
- func IsIntType(kind reflect.Kind) bool
- func IsNil(v interface{}) bool
- func MapLen(m interface{}) int
- func ReflectInt(v reflect.Value) int64
- func SliceCap(slice interface{}) int
- func SliceLen(slice interface{}) int
- func StringToBytes(s string) []byte
- func TypedMemMove(rtype *RType, dst, src unsafe.Pointer)
- func TypedSliceCopy(elemRType *RType, dst, src SliceHeader) int
- func UnpackSlice(slice interface{}) (*EmptyInterface, *SliceHeader)
- type EmptyInterface
- type RType
- func (t *RType) Align() int
- func (t *RType) AssignableTo(u reflect.Type) bool
- func (t *RType) Bits() int
- func (t *RType) ChanDir() reflect.ChanDir
- func (t *RType) Comparable() bool
- func (t *RType) ConvertibleTo(u reflect.Type) bool
- func (t *RType) Elem() *RType
- func (t *RType) Field(i int) reflect.StructField
- func (t *RType) FieldAlign() int
- func (t *RType) FieldByIndex(index []int) reflect.StructField
- func (t *RType) FieldByName(name string) (reflect.StructField, bool)
- func (t *RType) FieldByNameFunc(match func(string) bool) (reflect.StructField, bool)
- func (t *RType) IfaceIndir() bool
- func (t *RType) Implements(u reflect.Type) bool
- func (t *RType) In(i int) reflect.Type
- func (t *RType) IsVariadic() bool
- func (t *RType) Key() *RType
- func (t *RType) Kind() reflect.Kind
- func (t *RType) Len() int
- func (t *RType) Method(a0 int) reflect.Method
- func (t *RType) MethodByName(a0 string) (reflect.Method, bool)
- func (t *RType) Name() string
- func (t *RType) NumField() int
- func (t *RType) NumIn() int
- func (t *RType) NumMethod() int
- func (t *RType) NumOut() int
- func (t *RType) Out(i int) reflect.Type
- func (t *RType) PackInterface(word unsafe.Pointer) interface{}
- func (t *RType) PkgPath() string
- func (t *RType) Pointer() unsafe.Pointer
- func (t *RType) Size() uintptr
- func (t *RType) String() string
- func (t *RType) ToType() reflect.Type
- type SliceHeader
- type StringHeader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArrayAt ¶
ArrayAt returns the i-th element of p, an array whose elements are elemSize bytes wide. The array pointed at by p must have at least i+1 elements: it is invalid (but impossible to check here) to pass i >= len, because then the result will point outside the array.
func BytesToString ¶
BytesToString converts a []byte to string without copying memory.
It uses unsafe tricks, it may panic your program or result unpredictable behavior.
func CastInt ¶
func CastInt(v interface{}) int64
CastInt returns an integer v's value as int64. v must be an integer, else it panics.
func CastIntPointer ¶
CastIntPointer returns ptr's value as int64, the underlying value is cast to int64 using unsafe tricks according kind.
If ptr is not pointed to an integer or kind does not match ptr, the behavior is undefined, it may panic or return incorrect value.
func IsIdenticalThriftType ¶
IsIdenticalThriftType checks whether the given two object types have same struct fields and memory layout, in case that a field's name does not match, but the thrift tag's first two fields match, it also considers the field matches.
It is almost same with IsIdenticalType, but helps the situation that different Thrift generators which generate different field names.
If two types are identical, it is expected that unsafe pointer casting between the two types won't crash the program. If the given two types are not identical, the returned diff message contains the detail difference.
func IsIdenticalType ¶
IsIdenticalType checks whether the given two object types have same struct fields and memory layout (same order, same name and same type). It's useful to check generated types are exactly same in different packages, e.g. Thrift, Protobuf, Msgpack, etc.
If two types are identical, it is expected that unsafe pointer casting between the two types won't crash the program. If the given two types are not identical, the returned diff message contains the detail difference.
func IsNil ¶
func IsNil(v interface{}) bool
IsNil tells whether v is nil or the underlying data is nil.
func MapLen ¶
func MapLen(m interface{}) int
MapLen returns the length of the given map interface{} value. The provided m must be a map, else it panics.
func ReflectInt ¶
ReflectInt returns v's underlying value as int64. It panics if v is not a integer value.
func SliceCap ¶
func SliceCap(slice interface{}) int
SliceCap returns the capacity of the given slice interface{} value. The provided slice must be a slice, else it panics.
func SliceLen ¶
func SliceLen(slice interface{}) int
SliceLen returns the length of the given slice interface{} value. The provided slice must be a slice, else it panics.
func StringToBytes ¶
StringToBytes converts a string to []byte without copying memory.
It uses unsafe tricks, it may panic your program or result unpredictable behavior.
func TypedMemMove ¶
TypedMemMove exports the typedmemmove function in reflect package.
func TypedSliceCopy ¶
func TypedSliceCopy(elemRType *RType, dst, src SliceHeader) int
TypedSliceCopy exports the typedslicecopy function in reflect package.
func UnpackSlice ¶
func UnpackSlice(slice interface{}) (*EmptyInterface, *SliceHeader)
UnpackSlice unpacks the given slice interface{} to the underlying EmptyInterface and SliceHeader. It panics if param slice is not a slice.
Types ¶
type EmptyInterface ¶
EmptyInterface is the header for an interface{} value. It's a copy type of runtime.eface.
func EfaceOf ¶
func EfaceOf(ep *interface{}) *EmptyInterface
EfaceOf casts the empty interface{} pointer to an EmptyInterface pointer.
type RType ¶
type RType struct{}
func MapOf ¶
MapOf returns the map type with the given key and element types. For example, if k represents int and e represents string, MapOf(k, e) represents map[int]string.
If the key type is not a valid map key type (that is, if it does not implement Go's == operator), MapOf panics.
func PtrTo ¶
PtrTo returns the pointer type with element t. For example, if t represents type Foo, PtrTo(t) represents *Foo.
func RTypeOf ¶
func RTypeOf(v interface{}) *RType
RTypeOf returns the underlying rtype pointer of the given interface{} value.
func SliceOf ¶
SliceOf returns the slice type with element type t. For example, if t represents int, SliceOf(t) represents []int.
func (*RType) Comparable ¶
func (*RType) FieldAlign ¶
func (*RType) FieldByIndex ¶
func (t *RType) FieldByIndex(index []int) reflect.StructField
func (*RType) FieldByName ¶
func (t *RType) FieldByName(name string) (reflect.StructField, bool)
func (*RType) FieldByNameFunc ¶
func (*RType) IfaceIndir ¶
func (*RType) IsVariadic ¶
func (*RType) PackInterface ¶
type SliceHeader ¶
type SliceHeader = unsafeheader.Slice
SliceHeader is the runtime representation of a slice.
Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the data it references will not be garbage collected.
type StringHeader ¶
type StringHeader = unsafeheader.String
StringHeader is the runtime representation of a string.
Unlike reflect.StringHeader, its Data field is sufficient to guarantee the data it references will not be garbage collected.