codec

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PartSize int = 0x8000
)

Variables

This section is empty.

Functions

func EncodeReq

func EncodeReq(writer netpoll.Writer, req *ReqPack) (err error)

func PutPayloadCode

func PutPayloadCode(name string, v PayloadCodec)

PutPayloadCode puts the desired payload codec to message.

func WriteResp

func WriteResp(writer netpoll.Writer, msg *RespPack) (err error)

func WriteStringToBuf

func WriteStringToBuf(buffer *bytes.Buffer, b []byte) error

Types

type Addr

type Addr struct {
	Id   uint32
	Name string
}

func GetServiceAddress

func GetServiceAddress(address interface{}) (*Addr, error)

func (*Addr) String

func (addr *Addr) String() string

type PayloadCodec

type PayloadCodec interface {
	Marshal(msg any) ([]byte, error)
	Unmarshal(in []byte, msg any) error
	IsNull(in []byte) bool
	Name() string
}

func GetPayloadCodec

func GetPayloadCodec(name string) (PayloadCodec, bool)

default registered json/msgpack GetPayloadCodec gets desired payload codec from name.

type ReqPack

type ReqPack struct {
	Addr    Addr   // 4-7
	Session uint32 // 8-11
	Push    bool   // push package don't need to response
	Method  string
	Payload []byte
}

func DecodeReq

func DecodeReq(pkg netpoll.Reader, pendingPack map[uint32]*ReqPack) (*ReqPack, error)

func (*ReqPack) IsPush

func (req *ReqPack) IsPush() bool

type RespPack

type RespPack struct {
	Ok      bool   // msg pack/unpack
	Session uint32 // DWORD
	Payload []byte // 0: errmsg  1: msg  2: DWORD size   3/4: msg
}

func ReadResp

func ReadResp(pkg netpoll.Reader, pendingResp map[uint32]*RespPack) (resp *RespPack, err error)

type RetType

type RetType byte
const (
	RespTypeErr    RetType = 0
	RespTypeOk     RetType = 1
	RespTypeMBegin RetType = 2
	RespTypeMPart  RetType = 3
	RespTypeMEnd   RetType = 4
)

Jump to

Keyboard shortcuts

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