codec

package
v0.0.0-...-935d597 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCodec = NewCodec()
View Source
var NewCodec = func() Codec {
	return &defaultCodec{}
}

Functions

func RegisterCodec

func RegisterCodec(name string, codec Codec)

Types

type Codec

type Codec interface {
	Encode([]byte, MsgType) ([]byte, error)
	Decode([]byte) (*Frame, error)
}

func GetCodec

func GetCodec(name string) Codec

type Frame

type Frame struct {
	Header *FrameHeader // header of Frame
	Data   []byte       // serialized data
}

type FrameHeader

type FrameHeader struct {
	MsgTypeStart uint8  // start of frame
	Length       uint32 // total packet length
	MsgTypeEnd   uint8  // end of frame
}

type MsgType

type MsgType int32
const (
	RPC          MsgType = 1
	Broadcast    MsgType = 2
	FrameHeadLen         = 6
)

Jump to

Keyboard shortcuts

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