codec

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NilCodecID 空的编解码器id.
	NilCodecID byte = 0
	// NilCodecName 空的编解码器名称.
	NilCodecName string = ""
)
View Source
const (
	NameForm = "form"
	IdForm   = 'f'
)
View Source
const (
	NameJson = "json"
	IdJson   = 'j'
)
View Source
const (
	NamePlain = "plain"
	IdPlain   = 's'
)
View Source
const (
	NameXml = "xml"
	IdXml   = 'x'
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(codecID byte, v interface{}) ([]byte, error)

Marshal 使用指定编解码器编码

func Reg

func Reg(codec Codec)

Reg 注册编解码器到容器

func Unmarshal

func Unmarshal(codecID byte, data []byte, v interface{}) error

Unmarshal 使用指定编解码器解码

Types

type Codec

type Codec interface {
	ID() byte
	Name() string
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

Codec 消息内容的编解码器

func Get

func Get(codecID byte) (Codec, error)

Get 通过编解码器的id获取编解码器对象

func GetByName

func GetByName(codecName string) (Codec, error)

GetByName 通过编解码器的名字获取编解码器对象

type FormCodec added in v0.0.3

type FormCodec struct{}

FormCodec url encode codec

func (FormCodec) ID added in v0.0.3

func (FormCodec) ID() byte

ID returns codec id.

func (FormCodec) Marshal added in v0.0.3

func (FormCodec) Marshal(v interface{}) ([]byte, error)

func (FormCodec) Name added in v0.0.3

func (FormCodec) Name() string

Name returns codec name.

func (FormCodec) Unmarshal added in v0.0.3

func (FormCodec) Unmarshal(data []byte, v interface{}) error

type JSONCodec

type JSONCodec struct{}

func (JSONCodec) ID

func (JSONCodec) ID() byte

func (JSONCodec) Marshal

func (JSONCodec) Marshal(v interface{}) ([]byte, error)

func (JSONCodec) Name

func (JSONCodec) Name() string

func (JSONCodec) Unmarshal

func (JSONCodec) Unmarshal(data []byte, v interface{}) error

type PlainCodec added in v0.0.3

type PlainCodec struct{}

PlainCodec plain text codec

func (PlainCodec) ID added in v0.0.3

func (PlainCodec) ID() byte

ID returns codec id.

func (PlainCodec) Marshal added in v0.0.3

func (PlainCodec) Marshal(v interface{}) ([]byte, error)

func (PlainCodec) Name added in v0.0.3

func (PlainCodec) Name() string

Name returns codec name.

func (PlainCodec) Unmarshal added in v0.0.3

func (PlainCodec) Unmarshal(data []byte, v interface{}) error

type XMLCodec added in v0.0.3

type XMLCodec struct{}

func (XMLCodec) ID added in v0.0.3

func (XMLCodec) ID() byte

ID returns codec id.

func (XMLCodec) Marshal added in v0.0.3

func (XMLCodec) Marshal(v interface{}) ([]byte, error)

func (XMLCodec) Name added in v0.0.3

func (XMLCodec) Name() string

Name returns codec name.

func (XMLCodec) Unmarshal added in v0.0.3

func (XMLCodec) Unmarshal(data []byte, v interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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