Documentation ¶
Index ¶
- func DecodeBool(v any, b bool) error
- func DecodeBytes(v any, data []byte) error
- func DecodeMap[K ~string, V any](dec Decoder, m *map[K]V) error
- func DecodeNil(v any) error
- func DecodeNumber(v any, n string) error
- func DecodeSlice[T comparable](dec Decoder, s *[]T) error
- func DecodeString(v any, s string) error
- func Keys[K comparable, V any](m map[K]V) []K
- func Must[T any](p **T) *T
- func Resize[S ~[]E, E any](s *S, i int) E
- func SortedKeys[K cmp.Ordered, V any](m map[K]V) []K
- type BoolDecoder
- type BytesDecoder
- type Codec
- type Decoder
- type ElementDecoder
- type FieldDecoder
- type Float
- type FloatDecoder
- type IntDecoder
- type Integer
- type NilDecoder
- type Resolver
- type Resolvers
- type Signed
- type StringDecoder
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeBool ¶
DecodeBool decodes a boolean value into v. If *v is a pointer to a bool, then a bool will be allocated. If v implements BoolDecoder, then DecodeBool(b) is called.
func DecodeBytes ¶
DecodeBytes decodes data into v. The following types are supported: []byte, BytesDecoder, encoding.BinaryUnmarshaler, and encoding.TextUnmarshaler.
func DecodeNumber ¶
DecodeNumber decodes a number encoded as a string into v. The following core types are supported: int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, and float64. Pointers to the above types are also supported, and will be allocated if necessary. The interface types IntDecoder, and FloatDecoder are also supported. If unable to decode into a numeric type, it will fall back to DecodeString.
func DecodeSlice ¶
func DecodeSlice[T comparable](dec Decoder, s *[]T) error
DecodeSlice adapts slice s into an ElementDecoder and decodes it.
func DecodeString ¶
DecodeString decodes s into v. The following types are supported: string, *string, and StringDecoder. It will fall back to DecodeBytes to attempt to decode into a byte slice or binary decoder.
func Must ¶
func Must[T any](p **T) *T
Must ensures that the pointer at *p is non-nil. If *p is nil, a new value of type T will be allocated.
func SortedKeys ¶
SortedKeys returns a slice of keys for map m. Map keys must conform to cmp.Ordered.
Types ¶
type BoolDecoder ¶
BoolDecoder is the interface implemented by types that can decode from a bool.
type BytesDecoder ¶
BytesDecoder is the interface implemented by types that can decode from a byte slice. It is similar to encoding.BinaryUnmarshaler and encoding.TextUnmarshaler.
type Codec ¶
type Codec any
Codec is any type that can encode or decode itself or an associated type.
type ElementDecoder ¶
ElementDecoder is the interface implemented by types that can decode 0-indexed elements, such as a slice or an array.
func Slice ¶
func Slice[E comparable](s *[]E) ElementDecoder
Slice returns an ElementDecoder for slice s.
type FieldDecoder ¶
FieldDecoder is the interface implemented by types that can decode fields, such as structs or maps.
func Map ¶
func Map[K ~string, V any](m *map[K]V) FieldDecoder
Map returns an FieldDecoder for map m.
type FloatDecoder ¶
FloatDecoder is the interface implemented by types that can decode from a floating-point value. See Float for the list of supported types.
type IntDecoder ¶
IntDecoder is the interface implemented by types that can decode from an integer value. See Integer for the list of supported types.
type NilDecoder ¶
type NilDecoder interface {
DecodeNil() error
}
NilDecoder is the interface implemented by types that can decode from nil.
type Resolver ¶
Resolver is the interface implemented by types that return a codec for the value at v. Values returned by Resolver should implement one or more encode or decode methods.
type Resolvers ¶
type Resolvers []Resolver
Resolvers is a slice of Resolver values. It also implements the Resolver interface.
func (Resolvers) ResolveCodec ¶
ResolveCodec walks the slice of Resolvers, returning the first non-nil value or an error.
type StringDecoder ¶
StringDecoder is the interface implemented by types that can decode from a string.