codec

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewCodecFuncMap map[CodecType]NewCodecFunc

Functions

This section is empty.

Types

type Codec

type Codec interface {
	io.Closer
	ReadHeader(*Header) error
	ReadBody(interface{}) error
	Write(*Header, interface{}) error
}

编解码器接口

func NewGobCodec

func NewGobCodec(conn io.ReadWriteCloser) Codec

type CodecType

type CodecType string
const (
	// gob 和 json 都是 go 语言自带的序列化方式
	GobType CodecType = "application/gob"
)

type GobCodec

type GobCodec struct {
	// contains filtered or unexported fields
}

func (*GobCodec) Close

func (g *GobCodec) Close() error

func (*GobCodec) ReadBody

func (g *GobCodec) ReadBody(body interface{}) error

func (*GobCodec) ReadHeader

func (g *GobCodec) ReadHeader(header *Header) error

func (*GobCodec) Write

func (g *GobCodec) Write(header *Header, body interface{}) (err error)
type Header struct {
	ServiceMethod string
	Seq           uint64
	Error         string
}

type NewCodecFunc

type NewCodecFunc func(io.ReadWriteCloser) Codec

编解码器的构造函数 将 IO 包起来,读/写都通过编解码器 codec 完成

Jump to

Keyboard shortcuts

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