Documentation
¶
Index ¶
- func BytesOf(obj any) []byte
- func BytesToSliceHeader(b []byte) *reflect.SliceHeader
- func CastBytesToString(b []byte) string
- func CastStringToBytes(s string) []byte
- func FieldByIndex[F any, T any, PTR Pointer[T]](obj PTR, idx int) *F
- func FieldByIndexInValue(v reflect.Value, idx int) reflect.Value
- func FieldByName[F any, T any, PTR Pointer[T]](obj PTR, fieldName string) *F
- func FieldByNameInValue(v reflect.Value, fieldName string) reflect.Value
- func FieldByPath[F any, T any, PTR Pointer[T]](obj PTR, path []string) *F
- func FieldByPathInValue(in reflect.Value, path []string) reflect.Value
- func SetPointerToBytes(pointerPointer interface{}, b []byte) error
- type ErrSliceTooShort
- type Pointer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToSliceHeader ¶
func BytesToSliceHeader(b []byte) *reflect.SliceHeader
func CastBytesToString ¶
CastBytesToString casts a slice of bytes to a string in an unsafe way: the string is not guaranteed to be immutable (since it just reuses the same headers as the slice of bytes, which is modifiable).
This is a zero-memory-allocation function.
func CastStringToBytes ¶
CastStringToBytes casts a string to a slice of bytes in an unsafe way: the string is not guaranteed to be immutable (since the returned slice has the same pointer underneath).
func FieldByIndex ¶
FieldByIndex receives a pointer to a struct into `obj` and returns a pointer to the value of the field with index `idx` (even if it's a private field), similarly to how `reflect.(*Value).Field` works.
It will panic if it was passed non-pointer or/and to non-structure to `obj`, or if field with index `idx` does not exist in the structure.
func FieldByIndexInValue ¶
FieldByIndexInValue does the same as FieldByIndex, but works with reflect.Value instead of interfaces.
func FieldByName ¶
FieldByName receives a pointer to a struct into `obj` and returns a pointer to the value of the field with name `fieldName` (even if it's a private field).
It will panic if it was passed non-pointer or/and to non-structure to `obj`, or if field `fieldName` does not exist in the structure.
func FieldByNameInValue ¶
FieldByNameInValue does the same as FieldByName, but works with reflect.Value instead of interfaces.
func FieldByPath ¶
FieldByPath receives a pointer to a struct into `obj` and returns a pointer to the value of the field by path `path` (even if there're private fields in the path).
`path` is a series of field names which are used to recursively deep into the structure to get the required field.
It will panic if it was passed non-pointer or/and to non-structure to `obj`, or if a field from the path does not exist in the structure.
func FieldByPathInValue ¶
FieldByPathInValue does the same as FieldByPath, but works with reflect.Value instead of interfaces.
func SetPointerToBytes ¶
Types ¶
type ErrSliceTooShort ¶
func (*ErrSliceTooShort) Error ¶
func (err *ErrSliceTooShort) Error() string