packet

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Plain = iota
	Popularity
	Zlib
	Brotli
)
View Source
const (
	HeartBeat
	HeartBeatResponse

	Notification

	RoomEnter
	RoomEnterResponse
)

Variables

This section is empty.

Functions

func EncodePacket

func EncodePacket(packet Packet) []byte

EncodePacket Encode

func NewEnterPacket

func NewEnterPacket(uid int, roomID int, key string) []byte

NewEnterPacket 构造进入房间的包 uid 可以为 0, key 在使用 broadcastlv 服务器的时候不需要

func NewHeartBeatPacket

func NewHeartBeatPacket() []byte

NewHeartBeatPacket 构造心跳包

Types

type Enter

type Enter struct {
	UID       int    `json:"uid"`
	RoomID    int    `json:"roomid"`
	ProtoVer  int    `json:"protover"`
	Platform  string `json:"platform"`
	ClientVer string `json:"clientver"`
	Type      int    `json:"type"`
	Key       string `json:"key"`
}

type Packet

type Packet struct {
	PacketLength    int // PacketLength 在 build 时会计算
	HeaderLength    int // HeaderLength 大概是固定值 16
	ProtocolVersion uint16
	Operation       uint32
	SequenceID      int
	Body            []byte
}

func DecodePacket

func DecodePacket(data []byte) Packet

DecodePacket Decode

func NewPacket

func NewPacket(protocolVersion uint16, operation uint32, body []byte) Packet

func NewPacketFromBytes

func NewPacketFromBytes(data []byte) Packet

func NewPlainPacket

func NewPlainPacket(operation int, body []byte) Packet

NewPlainPacket 构造新的 Plain 包 对外暴露的方法中 operation 全部使用int

func Slice

func Slice(data []byte) []Packet

func (*Packet) Build

func (p *Packet) Build() []byte

func (Packet) Parse

func (p Packet) Parse() []Packet

func (*Packet) Unmarshal

func (p *Packet) Unmarshal(v interface{}) error

Jump to

Keyboard shortcuts

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