codec

package
v0.0.0-...-ff711b1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MagicNumber = 0x3bef5c

Variables

View Source
var NewCodecFuncMap map[Type]NewCodecFunc

Functions

This section is empty.

Types

type Codec

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

func NewGobCodec

func NewGobCodec(conn io.ReadWriteCloser) Codec

func NewJsonCodec

func NewJsonCodec(conn io.ReadWriteCloser) Codec

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 any) error

func (*GobCodec) ReadHeader

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

func (*GobCodec) Write

func (g *GobCodec) Write(header *Header, body any) (err error)
type Header struct {
	ServiceMethod string //format "Service.Method"
	Seq           uint64 //req id
	Error         string
}

type JsonCodec

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

func (*JsonCodec) Close

func (j *JsonCodec) Close() error

func (*JsonCodec) ReadBody

func (j *JsonCodec) ReadBody(body any) error

func (*JsonCodec) ReadHeader

func (j *JsonCodec) ReadHeader(header *Header) error

func (*JsonCodec) Write

func (j *JsonCodec) Write(header *Header, body any) (err error)

type NewCodecFunc

type NewCodecFunc func(closer io.ReadWriteCloser) Codec

type Option

type Option struct {
	MagicNumber int  // MagicNumber marks this's a geerpc request
	CodecType   Type // client may choose different Codec to encode body
}

type Type

type Type string
const (
	GobType  Type = "application/gob"
	JsonType Type = "application/json"
)

Jump to

Keyboard shortcuts

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