Documentation
¶
Overview ¶
Package encoder supports to encode and decode structs in multiple formats.
Index ¶
- func AddEncodersExtension(t hint.Type, ext string) (bool, error)
- func Decode[T any](enc Encoder, b []byte, v *T) error
- func DecodeReader[T any](enc Encoder, r io.Reader, v *T) error
- func EncodersExtension(t hint.Type) (string, bool)
- func Ptr(i interface{}) (ptr reflect.Value, elem reflect.Value)
- type DecodeDetail
- type DecodeFunc
- type Encoder
- type Encoders
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DecodeDetail ¶
type DecodeDetail struct {
Instance interface{}
Decode DecodeFunc
Desc string
Hint hint.Hint
}
func AnalyzeSetHinter ¶
func AnalyzeSetHinter(d DecodeDetail, v interface{}) DecodeDetail
func (DecodeDetail) IsValid ¶
func (d DecodeDetail) IsValid([]byte) error
type Encoder ¶
type Encoder interface {
hint.Hinter
Add(DecodeDetail) error
AddHinter(hint.Hinter) error
Marshal(interface{}) ([]byte, error) // NOTE native marshaler func
Unmarshal([]byte, interface{}) error // NOTE native unmarshaler func
StreamEncoder(io.Writer) util.StreamEncoder
StreamDecoder(io.Reader) util.StreamDecoder
Decode([]byte) (interface{}, error) // NOTE decode by hint inside []byte
DecodeWithHint([]byte, hint.Hint) (interface{}, error) // NOTE decode []byte by given hint
DecodeWithHintType([]byte, hint.Type) (interface{}, error) // NOTE decode []byte by given type
DecodeWithFixedHintType(string, int) (interface{}, error) // NOTE decode string by fixed type size
DecodeSlice([]byte) ([]interface{}, error) // NOTE decode sliced data
DecodeMap([]byte) (map[string]interface{}, error) // NOTE decode map data
}
type Encoders ¶
type Encoders struct {
*hint.CompatibleSet[Encoder]
// contains filtered or unexported fields
}
func NewEncoders ¶
func (*Encoders) AddDetail ¶
func (encs *Encoders) AddDetail(d DecodeDetail) error
func (*Encoders) AddEncoder ¶
Click to show internal directories.
Click to hide internal directories.