encoding

package
v0.0.0-...-145bb91 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorTypeNotFit = errors.New("msg not proto.Message type")

Functions

func SetByteOrder

func SetByteOrder(order binary.ByteOrder)

SetByteOrder 修改字节序,默认小端序

func SetDefaultEncodeType

func SetDefaultEncodeType(n EncodeType)

SetDefaultEncodeType 修改默认编码类型,默认 encoding/gob 编码

Types

type Binary

type Binary struct {
	ByteOrder binary.ByteOrder
}

Binary 二进制编码

func (*Binary) Marshal

func (b *Binary) Marshal(data interface{}) ([]byte, error)

func (*Binary) Unmarshal

func (b *Binary) Unmarshal(buf []byte, data interface{}) error

type EncDecoder

type EncDecoder interface {
	// Unmarshal 反序列化
	Unmarshal(buf []byte, data interface{}) error
	// Marshal 序列化
	Marshal(data interface{}) ([]byte, error)
}

EncDecoder 应用层数据序列化方式

func GetEncoding

func GetEncoding(n EncodeType) (EncDecoder, bool)

GetEncoding 获取指定的编码器 返回编码器和是否存在

type EncodeType

type EncodeType int

EncodeType 编码器类型

const (
	TypeNil EncodeType = iota
	TypeGPB
	TypeBinary
	TypeGob
	TypeJson
	TypeMax
)

func TypeTest

func TypeTest(msg interface{}) EncodeType

TypeTest 根据消息类型判断使用什么编码方式

type Encoding

type Encoding struct {
	DefaultEncodeType EncodeType
	// contains filtered or unexported fields
}

Encoding 编码管理器

func NewEncoding

func NewEncoding() *Encoding

NewEncoding 创建编码管理器

func (*Encoding) GetEncoding

func (e *Encoding) GetEncoding(n EncodeType) (EncDecoder, bool)

GetEncoding 获取指定的编码器 返回编码器和是否存在

func (*Encoding) SetByteOrder

func (e *Encoding) SetByteOrder(order binary.ByteOrder)

SetByteOrder 修改字节序,默认小端序

func (*Encoding) TypeTest

func (e *Encoding) TypeTest(msg interface{}) EncodeType

TypeTest 根据消息类型判断使用什么编码方式

type GPB

type GPB struct {
}

GPB Google's protocol

func (*GPB) Marshal

func (p *GPB) Marshal(data interface{}) ([]byte, error)

func (*GPB) Unmarshal

func (p *GPB) Unmarshal(buf []byte, data interface{}) error

type Gob

type Gob struct {
}

Gob encoding/gob

func (*Gob) Marshal

func (d *Gob) Marshal(data interface{}) ([]byte, error)

func (*Gob) Unmarshal

func (d *Gob) Unmarshal(buf []byte, data interface{}) error

type JSON

type JSON struct {
}

JSON json编码

func (*JSON) Marshal

func (J *JSON) Marshal(data interface{}) ([]byte, error)

func (*JSON) Unmarshal

func (J *JSON) Unmarshal(buf []byte, data interface{}) error

type Nil

type Nil struct {
}

func (*Nil) Marshal

func (n *Nil) Marshal(data interface{}) ([]byte, error)

func (*Nil) Unmarshal

func (n *Nil) Unmarshal(buf []byte, data interface{}) error

Jump to

Keyboard shortcuts

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