encoding

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JsonName  = "json"
	ProtoName = "proto"
	XmlName   = "xml"
)

Variables

This section is empty.

Functions

func RegisterCodec

func RegisterCodec(codec Codec)

RegisterCodec 注册提供的编解码器与各传输层一起使用.

Types

type Codec

type Codec interface {
	// Marshal 返回将v一定格式导出.
	Marshal(v interface{}) ([]byte, error)
	// Unmarshal 编解码器解析data的数据,并将结果存储在v指向的值中.
	Unmarshal(data []byte, v interface{}) error
	// Name 返回编解码器实现的名称。返回的字符串将在传输中用作内容类型的一部分.结果必须是静态的;结果不能在调用之间更改.
	Name() string
}

Codec 定义传输用于编码和解码消息的接口. 注意:此接口的实现必须是线程安全的.

func GetCodec

func GetCodec(contentSubtype string) Codec

GetCodec 通过contentSubtype获取注册的编解码器,如果没有为contentSubtype注册任何编解码器,则返回nil.

contentSubtype内的字母应该为小写.

Jump to

Keyboard shortcuts

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