codec

package
v0.0.0-...-6674cbf Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewCodecFuncMap map[Type]NewCodecFunc

Functions

This section is empty.

Types

type Codec

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

func NewGobCodec

func NewGobCodec(conn io.ReadWriteCloser) Codec

NewGobCodec 创建gob编码器

type GobCodec

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

func (*GobCodec) Close

func (c *GobCodec) Close() error

func (*GobCodec) ReadBody

func (c *GobCodec) ReadBody(body any) error

func (*GobCodec) ReadHeader

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

func (*GobCodec) Write

func (c *GobCodec) Write(header *Header, body any) (err error)
type Header struct {
	// 请求方法,格式为:服务名.方法名
	ServiceMethod string
	// 序列号,区分不同请求
	Seq int
	// 错误信息
	Error string
}

Header 请求头

type NewCodecFunc

type NewCodecFunc func(conn io.ReadWriteCloser) Codec

NewCodecFunc 创建编码器函数

type Type

type Type string

Type 编码器类型

const (
	GobType      Type = "application/gob"
	JSONType     Type = "application/json"
	ProtobufType Type = "application/x-protobuf"
)

Jump to

Keyboard shortcuts

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