protocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MulanPSL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtoIDHeartbeatReq = uint32(1)
	ProtoIDHeartbeatRsp = uint32(2)
	ProtoIDEchoReq      = uint32(3)
	ProtoIDEchoRsp      = uint32(4)
	ProtoIDSignInReq    = uint32(5)
	ProtoIDSignInRsp    = uint32(6)
	ProtoIDUDPHelloReq  = uint32(225)
	ProtoIDUDPHelloRsp  = uint32(226)
)

ProtoID

View Source
const (
	ErrCodeOK       = uint32(0) //正确
	ErrCodeFail     = uint32(1) //总之失败
	ErrCodeUnknown  = uint32(2) //未知错误
	ErrCodeInvalid  = uint32(3) //无效
	ErrCodeNotExist = uint32(4) //不存在
	ErrCodeTimeout  = uint32(5) //超时
)

ErrorCode

Variables

This section is empty.

Functions

func RegMessageDef

func RegMessageDef(def Message)

Types

type DefineST

type DefineST interface {
	Name() string
	NewST() DefineST

	Encode() ([]byte, error)
	Decode([]byte) error

	String() string
}

type EchoReq

type EchoReq struct {
	Text string `json:"text,omitempty"`
}

消息: 回声

func NewEchoReq

func NewEchoReq() *EchoReq

func (*EchoReq) Decode

func (st *EchoReq) Decode(bs []byte) error

func (*EchoReq) Encode

func (st *EchoReq) Encode() ([]byte, error)

func (*EchoReq) Name

func (st *EchoReq) Name() string

func (*EchoReq) New

func (st *EchoReq) New() Message

func (*EchoReq) NewST

func (st *EchoReq) NewST() DefineST

func (*EchoReq) ProtoID

func (st *EchoReq) ProtoID() uint32

func (*EchoReq) String

func (st *EchoReq) String() string

type EchoRsp

type EchoRsp struct {
	Text string `json:"text,omitempty"`
}

func NewEchoRsp

func NewEchoRsp() *EchoRsp

func (*EchoRsp) Decode

func (st *EchoRsp) Decode(bs []byte) error

func (*EchoRsp) Encode

func (st *EchoRsp) Encode() ([]byte, error)

func (*EchoRsp) Name

func (st *EchoRsp) Name() string

func (*EchoRsp) New

func (st *EchoRsp) New() Message

func (*EchoRsp) NewST

func (st *EchoRsp) NewST() DefineST

func (*EchoRsp) ProtoID

func (st *EchoRsp) ProtoID() uint32

func (*EchoRsp) String

func (st *EchoRsp) String() string
type Header struct {
	CheckSum string     `json:"cs,omitempty"`
	ProtoID  uint32     `json:"p,omitempty"`
	Rsp      *HeaderRsp `json:"rsp,omitempty"`
	Seq      uint64     `json:"s,omitempty"`
	Tms      uint64     `json:"t,omitempty"`
}

消息头(header)

func NewHeader added in v0.1.0

func NewHeader() *Header

func (*Header) Decode added in v0.1.0

func (st *Header) Decode(bs []byte) error

func (*Header) Encode added in v0.1.0

func (st *Header) Encode() ([]byte, error)

func (*Header) Name added in v0.1.0

func (st *Header) Name() string

func (*Header) NewST added in v0.1.0

func (st *Header) NewST() DefineST

func (*Header) String added in v0.1.0

func (st *Header) String() string

type HeaderRsp

type HeaderRsp struct {
	ErrCode    uint32 `json:"ec,omitempty"`
	ErrMessage string `json:"em,omitempty"`
	RequestSeq uint64 `json:"rs,omitempty"`
	RequestTms uint64 `json:"rt,omitempty"`
}

func NewHeaderRsp

func NewHeaderRsp() *HeaderRsp

func (*HeaderRsp) Decode

func (st *HeaderRsp) Decode(bs []byte) error

func (*HeaderRsp) Encode

func (st *HeaderRsp) Encode() ([]byte, error)

func (*HeaderRsp) Name

func (st *HeaderRsp) Name() string

func (*HeaderRsp) NewST

func (st *HeaderRsp) NewST() DefineST

func (*HeaderRsp) String

func (st *HeaderRsp) String() string

type HeartbeatReq

type HeartbeatReq struct {
}

消息: 心跳

func NewHeartbeatReq

func NewHeartbeatReq() *HeartbeatReq

func (*HeartbeatReq) Decode

func (st *HeartbeatReq) Decode(bs []byte) error

func (*HeartbeatReq) Encode

func (st *HeartbeatReq) Encode() ([]byte, error)

func (*HeartbeatReq) Name

func (st *HeartbeatReq) Name() string

func (*HeartbeatReq) New

func (st *HeartbeatReq) New() Message

func (*HeartbeatReq) NewST

func (st *HeartbeatReq) NewST() DefineST

func (*HeartbeatReq) ProtoID

func (st *HeartbeatReq) ProtoID() uint32

func (*HeartbeatReq) String

func (st *HeartbeatReq) String() string

type HeartbeatRsp

type HeartbeatRsp struct {
	//心跳的response被设计为投递模式, 所以需要显式的时间回执
	BackTms uint64 `json:"backTms,omitempty"`
}

func NewHeartbeatRsp

func NewHeartbeatRsp() *HeartbeatRsp

func (*HeartbeatRsp) Decode

func (st *HeartbeatRsp) Decode(bs []byte) error

func (*HeartbeatRsp) Encode

func (st *HeartbeatRsp) Encode() ([]byte, error)

func (*HeartbeatRsp) Name

func (st *HeartbeatRsp) Name() string

func (*HeartbeatRsp) New

func (st *HeartbeatRsp) New() Message

func (*HeartbeatRsp) NewST

func (st *HeartbeatRsp) NewST() DefineST

func (*HeartbeatRsp) ProtoID

func (st *HeartbeatRsp) ProtoID() uint32

func (*HeartbeatRsp) String

func (st *HeartbeatRsp) String() string

type Message

type Message interface {
	DefineST

	ProtoID() uint32
	New() Message
}

type Packet added in v0.1.0

type Packet struct {
	Header  *Header
	Payload []byte
	Message Message

	Owner any
}

func (*Packet) String added in v0.1.0

func (pac *Packet) String() string

type ProtocolSet added in v0.1.0

type ProtocolSet interface {
	New(id uint32) Message
	Encode(msg Message) ([]byte, error)
	Decode(id uint32, bs []byte) (Message, error)
}
var GlobalProtocolSet ProtocolSet = &defaultProtocolSet{}

type STConnectionConfig added in v0.1.0

type STConnectionConfig struct {
	ConfoundCode []byte `json:"confoundCode,omitempty"`
}

func NewSTConnectionConfig added in v0.1.0

func NewSTConnectionConfig() *STConnectionConfig

func (*STConnectionConfig) Decode added in v0.1.0

func (st *STConnectionConfig) Decode(bs []byte) error

func (*STConnectionConfig) Encode added in v0.1.0

func (st *STConnectionConfig) Encode() ([]byte, error)

func (*STConnectionConfig) Name added in v0.1.0

func (st *STConnectionConfig) Name() string

func (*STConnectionConfig) NewST added in v0.1.0

func (st *STConnectionConfig) NewST() DefineST

func (*STConnectionConfig) String added in v0.1.0

func (st *STConnectionConfig) String() string

type STServerStatus added in v0.1.0

type STServerStatus struct {
	ServerVersion string `json:"serverVersion,omitempty"`
}

func NewSTServerStatus added in v0.1.0

func NewSTServerStatus() *STServerStatus

func (*STServerStatus) Decode added in v0.1.0

func (st *STServerStatus) Decode(bs []byte) error

func (*STServerStatus) Encode added in v0.1.0

func (st *STServerStatus) Encode() ([]byte, error)

func (*STServerStatus) Name added in v0.1.0

func (st *STServerStatus) Name() string

func (*STServerStatus) NewST added in v0.1.0

func (st *STServerStatus) NewST() DefineST

func (*STServerStatus) String added in v0.1.0

func (st *STServerStatus) String() string

type SignInReq added in v0.1.0

type SignInReq struct {
}

消息: 服务配置

func NewSignInReq added in v0.1.0

func NewSignInReq() *SignInReq

func (*SignInReq) Decode added in v0.1.0

func (st *SignInReq) Decode(bs []byte) error

func (*SignInReq) Encode added in v0.1.0

func (st *SignInReq) Encode() ([]byte, error)

func (*SignInReq) Name added in v0.1.0

func (st *SignInReq) Name() string

func (*SignInReq) New added in v0.1.0

func (st *SignInReq) New() Message

func (*SignInReq) NewST added in v0.1.0

func (st *SignInReq) NewST() DefineST

func (*SignInReq) ProtoID added in v0.1.0

func (st *SignInReq) ProtoID() uint32

func (*SignInReq) String added in v0.1.0

func (st *SignInReq) String() string

type SignInRsp added in v0.1.0

type SignInRsp struct {
	ConnConfig   *STConnectionConfig `json:"connConfig,omitempty"`
	ConnID       uint64              `json:"connID,omitempty"`
	ServerStatus *STServerStatus     `json:"serverStatus,omitempty"`
}

func NewSignInRsp added in v0.1.0

func NewSignInRsp() *SignInRsp

func (*SignInRsp) Decode added in v0.1.0

func (st *SignInRsp) Decode(bs []byte) error

func (*SignInRsp) Encode added in v0.1.0

func (st *SignInRsp) Encode() ([]byte, error)

func (*SignInRsp) Name added in v0.1.0

func (st *SignInRsp) Name() string

func (*SignInRsp) New added in v0.1.0

func (st *SignInRsp) New() Message

func (*SignInRsp) NewST added in v0.1.0

func (st *SignInRsp) NewST() DefineST

func (*SignInRsp) ProtoID added in v0.1.0

func (st *SignInRsp) ProtoID() uint32

func (*SignInRsp) String added in v0.1.0

func (st *SignInRsp) String() string

type UDPHeader added in v0.1.0

type UDPHeader struct {
	Index uint64 `json:"i,omitempty"`
}

UDP的额外头部

func NewUDPHeader added in v0.1.0

func NewUDPHeader() *UDPHeader

func (*UDPHeader) Decode added in v0.1.0

func (st *UDPHeader) Decode(bs []byte) error

func (*UDPHeader) Encode added in v0.1.0

func (st *UDPHeader) Encode() ([]byte, error)

func (*UDPHeader) Name added in v0.1.0

func (st *UDPHeader) Name() string

func (*UDPHeader) NewST added in v0.1.0

func (st *UDPHeader) NewST() DefineST

func (*UDPHeader) String added in v0.1.0

func (st *UDPHeader) String() string

type UDPHelloReq added in v0.1.0

type UDPHelloReq struct {
	SignCode string `json:"signCode,omitempty"`
}

应为一个UDP客户端发送的第一个消息

func NewUDPHelloReq added in v0.1.0

func NewUDPHelloReq() *UDPHelloReq

func (*UDPHelloReq) Decode added in v0.1.0

func (st *UDPHelloReq) Decode(bs []byte) error

func (*UDPHelloReq) Encode added in v0.1.0

func (st *UDPHelloReq) Encode() ([]byte, error)

func (*UDPHelloReq) Name added in v0.1.0

func (st *UDPHelloReq) Name() string

func (*UDPHelloReq) New added in v0.1.0

func (st *UDPHelloReq) New() Message

func (*UDPHelloReq) NewST added in v0.1.0

func (st *UDPHelloReq) NewST() DefineST

func (*UDPHelloReq) ProtoID added in v0.1.0

func (st *UDPHelloReq) ProtoID() uint32

func (*UDPHelloReq) String added in v0.1.0

func (st *UDPHelloReq) String() string

type UDPHelloRsp added in v0.1.0

type UDPHelloRsp struct {
	Index uint64 `json:"index,omitempty"`
}

应为一个UDP客户端接收的第一个消息

func NewUDPHelloRsp added in v0.1.0

func NewUDPHelloRsp() *UDPHelloRsp

func (*UDPHelloRsp) Decode added in v0.1.0

func (st *UDPHelloRsp) Decode(bs []byte) error

func (*UDPHelloRsp) Encode added in v0.1.0

func (st *UDPHelloRsp) Encode() ([]byte, error)

func (*UDPHelloRsp) Name added in v0.1.0

func (st *UDPHelloRsp) Name() string

func (*UDPHelloRsp) New added in v0.1.0

func (st *UDPHelloRsp) New() Message

func (*UDPHelloRsp) NewST added in v0.1.0

func (st *UDPHelloRsp) NewST() DefineST

func (*UDPHelloRsp) ProtoID added in v0.1.0

func (st *UDPHelloRsp) ProtoID() uint32

func (*UDPHelloRsp) String added in v0.1.0

func (st *UDPHelloRsp) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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