codec

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMarshalUnimplemented   = errors.New("marshal is not implemented")
	ErrUnmarshalUnimplemented = errors.New("unmarshal is not implemented")
)
View Source
var JSON roboot.Codec = &FuncCodec{
	ContentTyp:  "application/json",
	MarshalFunc: json.Marshal,
	NewEncoderFunc: func(w io.Writer) roboot.Encoder {
		return json.NewEncoder(w)
	},
	UnmarshalFunc: json.Unmarshal,
	NewDecoderFunc: func(r io.Reader) roboot.Decoder {
		return json.NewDecoder(r)
	},
}
View Source
var XML roboot.Codec = &FuncCodec{
	ContentTyp:  "application/xml",
	MarshalFunc: xml.Marshal,
	NewEncoderFunc: func(w io.Writer) roboot.Encoder {
		return xml.NewEncoder(w)
	},
	UnmarshalFunc: xml.Unmarshal,
	NewDecoderFunc: func(r io.Reader) roboot.Decoder {
		return xml.NewDecoder(r)
	},
}

Functions

This section is empty.

Types

type FuncCodec

type FuncCodec struct {
	ContentTyp     string
	MarshalFunc    func(interface{}) ([]byte, error)
	NewEncoderFunc func(io.Writer) roboot.Encoder
	EncodeFunc     func(io.Writer, interface{}) error
	UnmarshalFunc  func([]byte, interface{}) error
	NewDecoderFunc func(io.Reader) roboot.Decoder
	DecodeFunc     func(io.Reader, interface{}) error
}

func (*FuncCodec) ContentType

func (f *FuncCodec) ContentType() string

func (*FuncCodec) Decode

func (f *FuncCodec) Decode(r io.Reader, v interface{}) error

func (*FuncCodec) Encode

func (f *FuncCodec) Encode(w io.Writer, v interface{}) error

func (*FuncCodec) Marshal

func (f *FuncCodec) Marshal(v interface{}) ([]byte, error)

func (*FuncCodec) NewDecoder

func (f *FuncCodec) NewDecoder(r io.Reader) roboot.Decoder

func (*FuncCodec) NewEncoder

func (f *FuncCodec) NewEncoder(w io.Writer) roboot.Encoder

func (*FuncCodec) Unmarshal

func (f *FuncCodec) Unmarshal(b []byte, v interface{}) error

type FuncDecoder

type FuncDecoder struct {
	DecodeFunc func(io.Reader, interface{}) error
	Reader     io.Reader
}

func (FuncDecoder) Decode

func (f FuncDecoder) Decode(v interface{}) error

type FuncEncoder

type FuncEncoder struct {
	EncodeFunc func(io.Writer, interface{}) error
	Writer     io.Writer
}

func (FuncEncoder) Encode

func (f FuncEncoder) Encode(v interface{}) error

Jump to

Keyboard shortcuts

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