codec

package
v0.0.0-...-cb81ebf Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCodec = NewCodec()
View Source
var DefaultMarshal = NewMarshal()
View Source
var NewCodec = func() Codec {
	return &defaultCodec{}
}
View Source
var NewMarshal = func() Marshaller {
	return &defaultMarshal{}
}

Functions

func RegisterCodec

func RegisterCodec(name string, codec Codec)

func RegisterMarshaller

func RegisterMarshaller(name string, marshaller Marshaller)

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 Marshaller

type Marshaller interface {
	Marshal(m protoreflect.ProtoMessage) ([]byte, error)
	Unmarshal(b []byte, m protoreflect.ProtoMessage) error
}

func GetMarshaller

func GetMarshaller(name string) Marshaller

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