network

package
v0.0.0-...-884197f Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PatternNone = iota
	PatternKick
)
View Source
const (
	HeaderSize = 12 // 包体长度(4byte) | seq(4byte) | 协议号(4byte)

)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientCodec

type ClientCodec struct{}

ClientCodec 客户端编解码器

func NewClientCodec

func NewClientCodec() *ClientCodec

NewClientCodec 创建新的客户端编解码器

func (*ClientCodec) Decode

func (c *ClientCodec) Decode(in []byte, check func(pid uint32) bool) ([]Message, error)

Decode 解码消息 [协议号(4byte)|seq(4byte,optional)|消息长度(4byte)|消息内容(bytes)]...

func (*ClientCodec) Encode

func (c *ClientCodec) Encode(data []byte, seq uint32, pid uint32) packet.IPacket

Encode 编码消息 [seq(4byte)|协议号(4byte)|消息长度(4byte)|消息内容(bytes)]

type ClientRequest

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

func NewClientRequest

func NewClientRequest(seq uint32, pid uint32, in []byte, session *Session) *ClientRequest

func (*ClientRequest) Response

func (r *ClientRequest) Response(data []byte, pid uint32) error

func (*ClientRequest) ResponseBatch

func (r *ClientRequest) ResponseBatch(msgs []Message) error

type Codec

type Codec struct{}

func (*Codec) Decode

func (c *Codec) Decode(in []byte) ([]Message, error)

Decode [协议号(4byte)|seq(4byte,optional)|消息长度(4byte)|消息内容(bytes)]...

func (*Codec) Encode

func (c *Codec) Encode(data []byte, seq uint32, pid uint32) (packet.IPacket, error)

Encode [协议号(4byte)|seq(4byte,optional)|消息长度(4byte)|消息内容(bytes)]...

func (*Codec) EncodeBatch

func (c *Codec) EncodeBatch(msgList []Message) (packet.IPacket, error)

EncodeBatch 消息类型(1byte) [协议号(4byte)|seq(4byte,optional)|消息长度(4byte)|消息内容(bytes)]...

type Message

type Message struct {
	Pid  uint32
	Seq  uint32
	Data []byte
}

type Session

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

func NewSession

func NewSession(uid int64, stream mux.IServerConn) *Session

NewSession 创建新的会话,自动分配全局唯一ID

func (*Session) Close

func (s *Session) Close()

Close 关闭会话,保证只执行一次

func (*Session) Decode

func (s *Session) Decode(data []byte) ([]Message, error)

func (*Session) Id

func (s *Session) Id() int64

func (*Session) Kick

func (s *Session) Kick() error

func (*Session) Push

func (s *Session) Push(data []byte, pid uint32) error

Push 直接发送消息,不需要序列号

func (*Session) PushBatch

func (s *Session) PushBatch(msgs []Message) error

func (*Session) Send

func (s *Session) Send(data []byte) error

Send 发送原始数据

func (*Session) SendData

func (s *Session) SendData(data []byte, seq uint32, pid uint32) error

SendMessage 发送需要编码的消息

func (*Session) SendMessageBatch

func (s *Session) SendMessageBatch(msgs []Message) error

func (*Session) Uid

func (s *Session) Uid() int64

Jump to

Keyboard shortcuts

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