encoding

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPRequestMarshaler = NewMarshaler(marshalHTTPRequest, unmarshalHTTPRequest, nil)
View Source
var HTTPResponseMarshaler = NewMarshaler(
	marshalHTTPResponse,
	unmarshalHTTPResponse,
	unmarshalHTTPResponseTo,
)
View Source
var Null = NewMarshaler(
	func(value interface{}) (b []byte, err error) {
		if value, ok := value.([]byte); ok {
			b = value
		} else {
			err = errors.New("expected a byte slice")
		}
		return
	},
	func(b []byte) (interface{}, error) { return b, nil },
	func(b []byte, target interface{}) (err error) {
		if target, ok := target.(*[]byte); ok {
			*target = b
		} else {
			err = errors.New("expect a byte slice pointer")
		}
		return
	},
)

Functions

This section is empty.

Types

type MarshalFunc

type MarshalFunc func(value interface{}) (b []byte, err error)

type Marshaler

type Marshaler interface {
	Marshal(value interface{}) (b []byte, err error)
	Unmarshal(b []byte) (result interface{}, err error)
	UnmarshalTo(b []byte, target interface{}) (err error)
}

func NewMarshaler

func NewMarshaler(marshalFunc MarshalFunc, unmarshalFunc UnmarshalFunc, unmarshalToFunc UnmarshalToFunc) Marshaler

type UnmarshalFunc

type UnmarshalFunc func(b []byte) (result interface{}, err error)

type UnmarshalToFunc

type UnmarshalToFunc func(b []byte, target interface{}) (err error)

Jump to

Keyboard shortcuts

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