codec

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NilCodecID 空的编解码器id.
	NilCodecID byte = 0
	// NilCodecName 空的编解码器名称.
	NilCodecName string = ""
)
View Source
const (
	NameJson = "json"
	IdJson   = 'j'
)

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 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

Jump to

Keyboard shortcuts

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