encoder

package
v0.0.2-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2023 License: GPL-3.0 Imports: 5 Imported by: 76

Documentation

Overview

Package encoder supports to encode and decode structs in multiple formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(enc Encoder, b []byte, v interface{}) error

func DecodeReader

func DecodeReader(enc Encoder, r io.Reader, v interface{}) error

func Ptr

func Ptr(i interface{}) (ptr reflect.Value, elem reflect.Value)

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 DecodeFunc

type DecodeFunc func([]byte, hint.Hint) (interface{}, 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
}

type Encoders

type Encoders struct {
	*hint.CompatibleSet
}

func NewEncoders

func NewEncoders() *Encoders

func (*Encoders) Find

func (encs *Encoders) Find(ht hint.Hint) Encoder

Directories

Path Synopsis
Package jsonenc support encoding and decoding by json.
Package jsonenc support encoding and decoding by json.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL