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
- 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 ¶
RType representing reflect.rtype for noescape trick. It maps the exported methods of reflect.Type.
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.
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.