Involved Source Filesswapper.go Package reflectlite implements lightweight version of reflect, not using
any package except for "runtime", "unsafe", and "internal/abi"value.goasm.s
Package-Level Type Names (total 20, in which 4 are exported)
/* sort exporteds by: | */
A Kind represents the specific kind of type that a Type represents.
The zero Kind is not a valid kind.
Type is the representation of a Go type.
Not all methods apply to all kinds of types. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of type before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run-time panic.
Type values are comparable, such as with the == operator,
so they can be used as map keys.
Two Type values are equal if they represent identical types. AssignableTo reports whether a value of the type is assignable to type u. Comparable reports whether values of this type are comparable. Elem returns a type's element type.
It panics if the type's Kind is not Ptr. Implements reports whether the type implements the interface type u. Kind returns the specific kind of this type. Name returns the type's name within its package for a defined type.
For other (non-defined) types it returns the empty string. PkgPath returns a defined type's package path, that is, the import path
that uniquely identifies the package, such as "encoding/base64".
If the type was predeclared (string, error) or not defined (*T, struct{},
[]int, or A where A is an alias for a non-defined type), the package path
will be the empty string. Size returns the number of bytes needed to store
a value of the given type; it is analogous to unsafe.Sizeof. String returns a string representation of the type.
The string representation may use shortened package names
(e.g., base64 instead of "encoding/base64") and is not
guaranteed to be unique among types. To test for type identity,
compare the Types directly.( Type) common() *abi.Type( Type) uncommon() *uncommonTypertype
Type : fmt.Stringer
Type : context.stringer
Type : runtime.stringer
func TypeOf(i any) Type
func Type.Elem() Type
func Value.Type() Type
func toType(t *abi.Type) Type
func Type.AssignableTo(u Type) bool
func Type.Implements(u Type) bool
var errors.errorType
Value is the reflection interface to a Go value.
Not all methods apply to all kinds of values. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of value before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run time panic.
The zero Value represents no value.
Its IsValid method returns false, its Kind method returns Invalid,
its String method returns "<invalid Value>", and all other methods panic.
Most functions and methods never return an invalid value.
If one does, its documentation states the conditions explicitly.
A Value can be used concurrently by multiple goroutines provided that
the underlying Go value can be used concurrently for the equivalent
direct operations.
To compare two Values, compare the results of the Interface method.
Using == on two Values does not compare the underlying values
they represent. flag holds metadata about the value.
The lowest bits are flag bits:
- flagStickyRO: obtained via unexported not embedded field, so read-only
- flagEmbedRO: obtained via unexported embedded field, so read-only
- flagIndir: val holds a pointer to the data
- flagAddr: v.CanAddr is true (implies flagIndir)
Value cannot represent method values.
The next five bits give the Kind of the value.
This repeats typ.Kind() except for method values.
The remaining 23+ bits give a method number for method values.
If flag.kind() != Func, code can assume that flagMethod is unset.
If ifaceIndir(typ), code can assume that flagIndir is set. Pointer-valued data or, if flagIndir is set, pointer to data.
Valid when either flagIndir is set or typ.pointers() is true. typ holds the type of the value represented by a Value. CanSet reports whether the value of v can be changed.
A Value can be changed only if it is addressable and was not
obtained by the use of unexported struct fields.
If CanSet returns false, calling Set or any type-specific
setter (e.g., SetBool, SetInt) will panic. Elem returns the value that the interface v contains
or that the pointer v points to.
It panics if v's Kind is not Interface or Pointer.
It returns the zero Value if v is nil. IsNil reports whether its argument v is nil. The argument must be
a chan, func, interface, map, pointer, or slice value; if it is
not, IsNil panics. Note that IsNil is not always equivalent to a
regular comparison with nil in Go. For example, if v was created
by calling ValueOf with an uninitialized interface variable i,
i==nil will be true but v.IsNil will panic as v will be the zero
Value. IsValid reports whether v represents a value.
It returns false if v is the zero Value.
If IsValid returns false, all other methods except String panic.
Most functions and methods never return an invalid Value.
If one does, its documentation states the conditions explicitly. Kind returns v's Kind.
If v is the zero Value (IsValid returns false), Kind returns Invalid. Len returns v's length.
It panics if v's Kind is not Array, Chan, Map, Slice, or String. Set assigns x to the value v.
It panics if CanSet returns false.
As in Go, x's value must be assignable to v's type. Type returns v's type. assignTo returns a value v that can be assigned directly to typ.
It panics if v is not assignable to typ.
For a conversion to an interface type, target is a suggested scratch space to use.( Value) kind() Kind mustBeAssignable panics if f records that the value is not assignable,
which is to say that either it was obtained using an unexported field
or it is not addressable. mustBeExported panics if f records that the value was obtained using
an unexported field. NumMethod returns the number of exported methods in the value's method set. pointer returns the underlying pointer represented by v.
v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer( Value) ro() flag
func ValueOf(i any) Value
func Value.Elem() Value
func unpackEface(i any) Value
func Value.assignTo(context string, dst *abi.Type, target unsafe.Pointer) Value
func Value.Set(x Value)
func packEface(v Value) any
func valueInterface(v Value) any
A ValueError occurs when a Value method is invoked on
a Value that does not support it. Such cases are documented
in the description of each method.KindKindMethodstring(*ValueError) Error() string
*ValueError : error
( flag) kind() Kind mustBeAssignable panics if f records that the value is not assignable,
which is to say that either it was obtained using an unexported field
or it is not addressable. mustBeExported panics if f records that the value was obtained using
an unexported field.( flag) ro() flag
const flagAddr
const flagEmbedRO
const flagIndir
const flagKindMask
const flagMethod
const flagRO
const flagStickyRO
mapType represents a map type. // internal bucket structure // size of bucket // map element (value) typeFlagsuint32 function for hashing keys (ptr to key, seed) -> hash // map key type // size of key slot // embedding is okay here (unlike reflect) because none of this is public // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type 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. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zerortype.Type.Size_uintptr // string form // extra type information flags // size of value slotrtypertype Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match.( mapType) AssignableTo(u Type) bool ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).( mapType) Common() *abi.Type( mapType) Comparable() bool( mapType) ExportedMethods() []abi.Method( mapType) FieldAlign() int FuncType returns t cast to a *FuncType, or nil if its tag does not match.( mapType) GcSlice(begin, end uintptr) []byte( mapType) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value.( mapType) Implements(u Type) bool( mapType) In(i int) Type InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.( mapType) Kind() abi.Kind( mapType) Len() int MapType returns t cast to a *MapType, or nil if its tag does not match.( mapType) Name() string( mapType) NumField() int( mapType) NumIn() int( mapType) NumMethod() int( mapType) NumOut() int( mapType) Out(i int) Type( mapType) PkgPath() string( mapType) Pointers() bool Size returns the size of data with type t.( mapType) String() string StructType returns t cast to a *StructType, or nil if its tag does not match. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil( mapType) common() *abi.Type( mapType) exportedMethods() []abi.Method( mapType) nameOff(off nameOff) abi.Name( mapType) typeOff(off typeOff) *abi.Type( mapType) uncommon() *uncommonType
mapType : fmt.Stringer
mapType : context.stringer
mapType : runtime.stringer
name is an encoded type name with optional extra data.
The first byte is a bit field containing:
1<<0 the name is exported
1<<1 tag data follows the name
1<<2 pkgPath nameOff follows the name and tag
The next two bytes are the data length:
l := uint16(data[1])<<8 | uint16(data[2])
Bytes [3:3+l] are the string data.
If tag data follows then bytes 3+l and 3+l+1 are the tag length,
with the data following.
If the import path follows, then 4 bytes at the end of
the data form a nameOff. The import path is only set for concrete
methods that are defined in a different package than their type.
If a name starts with "*", then the exported bit represents
whether the pointed to type is exported.bytes*byte( name) data(off int, whySafe string) *byte( name) embedded() bool( name) hasTag() bool( name) isExported() bool( name) name() string readVarint parses a varint as encoded by encoding/binary.
It returns the number of encoded bytes and the encoded value.( name) tag() string
// embedding is okay here (unlike reflect) because none of this is public // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type 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. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zeroType.Size_uintptr // string form // extra type information flags Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match.( rtype) AssignableTo(u Type) bool ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).( rtype) Common() *abi.Type( rtype) Comparable() bool( rtype) Elem() Type( rtype) ExportedMethods() []abi.Method( rtype) FieldAlign() int FuncType returns t cast to a *FuncType, or nil if its tag does not match.( rtype) GcSlice(begin, end uintptr) []byte( rtype) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value.( rtype) Implements(u Type) bool( rtype) In(i int) Type InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.( rtype) Key() Type( rtype) Kind() abi.Kind( rtype) Len() int MapType returns t cast to a *MapType, or nil if its tag does not match.( rtype) Name() string( rtype) NumField() int( rtype) NumIn() int( rtype) NumMethod() int( rtype) NumOut() int( rtype) Out(i int) Type( rtype) PkgPath() string( rtype) Pointers() bool Size returns the size of data with type t.( rtype) String() string StructType returns t cast to a *StructType, or nil if its tag does not match. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil( rtype) common() *abi.Type( rtype) exportedMethods() []abi.Method( rtype) nameOff(off nameOff) abi.Name( rtype) typeOff(off typeOff) *abi.Type( rtype) uncommon() *uncommonType
rtype : Type
rtype : fmt.Stringer
rtype : context.stringer
rtype : runtime.stringer
func toRType(t *abi.Type) rtype
uncommonType is present only for defined types or types with methods
(if T is a defined type, the uncommonTypes for T and *T have methods).
Using a pointer to this struct reduces the overall size required
to describe a non-defined type with no methods.
Package-Level Functions (total 26, in which 3 are exported)
Swapper returns a function that swaps the elements in the provided
slice.
Swapper panics if the provided interface is not a slice.
TypeOf returns the reflection Type that represents the dynamic type of i.
If i is a nil interface value, TypeOf returns nil.
ValueOf returns a new Value initialized to the concrete value
stored in the interface i. ValueOf(nil) returns the zero Value.
add returns p+x.
The whySafe string is ignored, so that the function still inlines
as efficiently as p+x, but all call sites should use the string to
record why the addition is safe, which is to say why the addition
does not cause x to advance to the very end of p's allocation
and therefore point incorrectly at the next block in memory.
arrayAt returns the i-th element of p,
an array whose elements are eltSize 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.
whySafe must explain why i < len. (Passing "i < len" is fine;
the benefit is to surface this assumption at the call site.)
implemented in runtime:
directlyAssignable reports whether a value x of type V can be directly
assigned (using memmove) to a value of type T.
https://golang.org/doc/go_spec.html#Assignability
Ignoring the interface rules (implemented elsewhere)
and the ideal constant rules (no ideal constants at run time).
resolveNameOff resolves a name offset from a base pointer.
The (*rtype).nameOff method is a convenience wrapper for this function.
Implemented in the runtime package.
resolveTypeOff resolves an *rtype offset from a base type.
The (*rtype).typeOff method is a convenience wrapper for this function.
Implemented in the runtime package.
toType converts from a *rtype to a Type that can be returned
to the client of package reflect. In gc, the only concern is that
a nil *rtype must be replaced by a nil Type, but in gccgo this
function takes care of ensuring that multiple *rtype for the same
type are coalesced into a single Type.
typedmemmove copies a value of type t to dst from src.
unpackEface converts the empty interface i to a Value.
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.