binder

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 14 Imported by: 6

Documentation

Index

Constants

View Source
const (
	MIMEJSON              string = "application/json"
	MIMEXML                      = "application/xml"
	MIMEXML2                     = "text/xml"
	MIMEPOSTForm                 = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTForm        = "multipart/form-data"
	MIMEPROTOBUF                 = "application/x-protobuf"
	MIMEMSGPACK                  = "application/x-msgpack"
	MIMEMSGPACK2                 = "application/msgpack"
	MIMEYAML                     = "application/x-yaml"
)

Content-Type MIME of the most common data formats.

View Source
const ContentType = "Content-Type"

Variables

View Source
var Json = jsonBinding{}

Functions

func Decode

func Decode(r io.Reader, i interface{}, t string) error

func Encode

func Encode(w io.Writer, i interface{}, t string) error

func Marshal

func Marshal(i interface{}, t string) ([]byte, error)

func Register

func Register(t string, handle Interface) error

func Unmarshal

func Unmarshal(b []byte, i interface{}, t string) error

Types

type Binder

type Binder struct {
	// contains filtered or unexported fields
}

Binder 只对非基础类型进行序列化,一般用于内部通信,双方明确指定类型

func New

func New(t string) (b *Binder)

func (*Binder) Decode

func (this *Binder) Decode(r io.Reader, i interface{}) (err error)

func (*Binder) Encode

func (this *Binder) Encode(w io.Writer, i interface{}) (err error)

func (*Binder) Marshal

func (this *Binder) Marshal(i interface{}) (b []byte, err error)

Marshal 将一个对象放入Message.data

func (*Binder) String

func (this *Binder) String() string

func (*Binder) Unmarshal

func (this *Binder) Unmarshal(b []byte, i interface{}) (err error)

Unmarshal 解析Message body

type Interface

type Interface interface {
	String() string
	Encode(io.Writer, interface{}) error //同Marshal
	Decode(io.Reader, interface{}) error //同Unmarshal
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

func Handle

func Handle(t string) (h Interface)

Jump to

Keyboard shortcuts

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