Documentation ¶
Index ¶
- Constants
- func Binary(reader io.Reader) ([]byte, error)
- func Int16(reader io.Reader) (int16, error)
- func Int32(reader io.Reader) (int32, error)
- func ToFixHeaderUint8(f Frame) uint8
- func Uint32(reader io.Reader) (uint32, error)
- func WriteBinary(b []byte, w io.Writer) error
- func WriteInt16(i int, w io.Writer) error
- func WriteUint32(v uint32, w io.Writer) error
- type ConnackPacket
- type ConnectPacket
- type Decoder
- func (d *Decoder) Binary() ([]byte, error)
- func (d *Decoder) BinaryAll() ([]byte, error)
- func (d *Decoder) Bytes(num int) ([]byte, error)
- func (d *Decoder) Int16() (int16, error)
- func (d *Decoder) Int32() (int32, error)
- func (d *Decoder) Int64() (int64, error)
- func (d *Decoder) Len() int
- func (d *Decoder) String() (string, error)
- func (d *Decoder) StringAll() (string, error)
- func (d *Decoder) Uint16() (uint16, error)
- func (d *Decoder) Uint32() (uint32, error)
- func (d *Decoder) Uint64() (uint64, error)
- func (d *Decoder) Uint8() (uint8, error)
- func (d *Decoder) Variable() (uint64, error)
- type DeviceFlag
- type DeviceLevel
- type DisconnectPacket
- type Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) Len() int
- func (e *Encoder) WriteBinary(b []byte)
- func (e *Encoder) WriteByte(b byte) error
- func (e *Encoder) WriteBytes(b []byte)
- func (e *Encoder) WriteInt(i int) error
- func (e *Encoder) WriteInt16(i int)
- func (e *Encoder) WriteInt32(i int32)
- func (e *Encoder) WriteInt64(i int64)
- func (e *Encoder) WriteString(str string)
- func (e *Encoder) WriteStringAll(str string)
- func (e *Encoder) WriteUint16(i uint16)
- func (e *Encoder) WriteUint32(i uint32)
- func (e *Encoder) WriteUint64(i uint64)
- func (e *Encoder) WriteUint8(i uint8)
- func (e *Encoder) WriteVariable(v int)
- type Frame
- type Framer
- type LiMaoProto
- type PacketDecodeFunc
- type PacketEncodeFunc
- type PacketType
- type PingPacket
- type PongPacket
- type Protocol
- type ReasonCode
- type RecvPacket
- type RecvackPacket
- type SendPacket
- type SendackPacket
- type Setting
Constants ¶
const ( // APP APP APP DeviceFlag = iota // WEB WEB WEB = 1 // SYSTEM 系统 SYSTEM = 2 )
const LatestVersion = 4
LatestVersion 最新版本
const MaxRemaingLength uint32 = 1024 * 1024
MaxRemaingLength 最大剩余长度 // 1<<28 - 1
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnackPacket ¶
type ConnackPacket struct { Framer ServerKey string // 通过客户端的RSA公钥加密的服务端DH公钥 Salt string // salt TimeDiff int64 // 客户端时间与服务器的差值,单位毫秒。 ReasonCode ReasonCode // 原因码 }
ConnackPacket 连接回执包
func (ConnackPacket) GetPacketType ¶
func (c ConnackPacket) GetPacketType() PacketType
GetPacketType 获取包类型
func (ConnackPacket) String ¶
func (c ConnackPacket) String() string
type ConnectPacket ¶
type ConnectPacket struct { Framer Version uint8 // 协议版本 ClientKey string // 客户端公钥 DeviceID string // 设备ID DeviceFlag DeviceFlag // 设备标示(同标示同账号互踢) ClientTimestamp int64 // 客户端当前时间戳(13位时间戳,到毫秒) UID string // 用户ID Token string // token }
ConnectPacket 连接包
func (ConnectPacket) GetPacketType ¶
func (c ConnectPacket) GetPacketType() PacketType
GetPacketType 包类型
func (ConnectPacket) String ¶
func (c ConnectPacket) String() string
func (ConnectPacket) ToFixHeaderUint8 ¶
func (c ConnectPacket) ToFixHeaderUint8() uint8
ToFixHeaderUint8 ToFixHeaderUint8
type DeviceFlag ¶
type DeviceFlag uint8
DeviceFlag 设备类型
func (DeviceFlag) String ¶
func (r DeviceFlag) String() string
type DeviceLevel ¶
type DeviceLevel uint8
DeviceLevel 设备等级
const ( // DeviceLevelSlave 从设备 DeviceLevelSlave DeviceLevel = 0 // DeviceLevelMaster 主设备 DeviceLevelMaster DeviceLevel = 1 )
type DisconnectPacket ¶
type DisconnectPacket struct { Framer ReasonCode ReasonCode // 断开原因代号 Reason string // 断开原因 }
DisconnectPacket 断开连接数据包
func (DisconnectPacket) GetPacketType ¶
func (c DisconnectPacket) GetPacketType() PacketType
GetPacketType 包类型
func (DisconnectPacket) String ¶
func (c DisconnectPacket) String() string
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder 编码者
func (*Encoder) WriteStringAll ¶
WriteStringAll WriteStringAll
type Frame ¶
type Frame interface { GetPacketType() PacketType GetRemainingLength() uint32 // GetPersist 是否存储 GetNoPersist() bool // GetRedDot 是否显示红点 GetRedDot() bool // GetsyncOnce 是否只被同步一次 GetsyncOnce() bool // 是否是重发的消息 GetDUP() bool }
Frame 接口
type Framer ¶
type Framer struct { PacketType PacketType RemainingLength uint32 // 控制报文总长度等于固定报头的长度加上剩余长度 NoPersist bool // 是否不持久化 RedDot bool // 是否显示红点 SyncOnce bool // 此消息只被同步或被消费一次 DUP bool // 是否是重发消息 }
Framer 包的基础framer
func (Framer) GetPacketType ¶
func (f Framer) GetPacketType() PacketType
GetPacketType GetPacketType
func (Framer) GetRemainingLength ¶
GetRemainingLength 包剩余长度
type LiMaoProto ¶
LiMaoProto 狸猫协议对象
func (*LiMaoProto) DecodePacket ¶
DecodePacket 解码包
func (*LiMaoProto) DecodePacketWithConn ¶
DecodePacketWithConn 解码包
func (*LiMaoProto) EncodePacket ¶
func (l *LiMaoProto) EncodePacket(packet interface{}, version uint8) ([]byte, error)
EncodePacket 编码包
type PacketDecodeFunc ¶
PacketDecodeFunc 包解码函数
type PacketEncodeFunc ¶
PacketEncodeFunc 包编码函数
type PacketType ¶
type PacketType uint8
PacketType 包类型
const ( Reserved PacketType = iota // 保留位 CONNECT // 客户端请求连接到服务器(c2s) CONNACK // 服务端收到连接请求后确认的报文(s2c) SEND // 发送消息(c2s) SENDACK // 收到消息确认的报文(s2c) RECV // 收取消息(s2c) RECVACK // 收取消息确认(c2s) PING //ping请求 PONG // 对ping请求的相应 DISCONNECT // 请求断开连接 )
包类型
func (PacketType) String ¶
func (p PacketType) String() string
type PingPacket ¶
type PingPacket struct {
Frame
}
PingPacket ping包
func (*PingPacket) GetPacketType ¶
func (p *PingPacket) GetPacketType() PacketType
GetPacketType 包类型
type PongPacket ¶
type PongPacket struct {
Frame
}
PongPacket pong包对ping的回应
func (*PongPacket) GetPacketType ¶
func (p *PongPacket) GetPacketType() PacketType
GetPacketType 包类型
type Protocol ¶
type Protocol interface { // DecodePacket 解码消息 DecodePacket(data []byte, version uint8) (Frame, int, error) // EncodePacket 编码消息 EncodePacket(packet interface{}, version uint8) ([]byte, error) }
Protocol Protocol
type ReasonCode ¶
type ReasonCode uint8
ReasonCode 原因码
const ( // ReasonError 错误 ReasonError ReasonCode = iota // ReasonSuccess 成功 ReasonSuccess // ReasonAuthFail 认证失败 ReasonAuthFail // ReasonSubscriberNotExist 订阅者在频道内不存在 ReasonSubscriberNotExist // ReasonInBlacklist 在黑名单列表里 ReasonInBlacklist // ReasonChannelNotExist 频道不存在 ReasonChannelNotExist // ReasonUserNotOnNode 用户没在节点上 ReasonUserNotOnNode // ReasonSenderOffline // 发送者离线了,这条消息将发不成功 ReasonSenderOffline // ReasonMsgKeyError 消息key错误 说明消息不合法 ReasonMsgKeyError // ReasonPayloadDecodeError payload解码失败 ReasonPayloadDecodeError // ReasonForwardSendPacketError 转发发送包失败 ReasonForwardSendPacketError // ReasonNotAllowSend 不允许发送消息 ReasonNotAllowSend )
func (ReasonCode) String ¶
func (r ReasonCode) String() string
type RecvPacket ¶
type RecvPacket struct { Framer Setting MsgKey string // 用于验证此消息是否合法(仿中间人篡改) MessageID int64 // 服务端的消息ID(全局唯一) MessageSeq uint32 // 消息序列号 (用户唯一,有序递增) ClientMsgNo string // 客户端唯一标示 Timestamp int32 // 服务器消息时间戳(10位,到秒) FromUID string // 发送者UID ChannelID string // 频道ID ChannelType uint8 // 频道类型 Payload []byte // 消息内容 }
RecvPacket 收到消息的包
func (*RecvPacket) GetPacketType ¶
func (r *RecvPacket) GetPacketType() PacketType
GetPacketType 获得包类型
func (*RecvPacket) String ¶
func (r *RecvPacket) String() string
type RecvackPacket ¶
RecvackPacket 对收取包回执
func (*RecvackPacket) GetPacketType ¶
func (s *RecvackPacket) GetPacketType() PacketType
GetPacketType 包类型
func (*RecvackPacket) String ¶
func (s *RecvackPacket) String() string
type SendPacket ¶
type SendPacket struct { Framer Setting MsgKey string // 用于验证此消息是否合法(仿中间人篡改) ClientSeq uint64 // 客户端提供的序列号,在客户端内唯一 ClientMsgNo string // 客户端消息唯一编号一般是uuid,为了去重 ChannelID string // 频道ID(如果是个人频道ChannelId为个人的UID) ChannelType uint8 // 频道类型(1.个人 2.群组) Payload []byte // 消息内容 }
SendPacket 发送包
func (*SendPacket) GetPacketType ¶
func (s *SendPacket) GetPacketType() PacketType
GetPacketType 包类型
func (*SendPacket) String ¶
func (s *SendPacket) String() string
type SendackPacket ¶
type SendackPacket struct { Framer MessageID int64 // 消息ID(全局唯一) MessageSeq uint32 // 消息序列号(用户唯一,有序) ClientSeq uint64 // 客户端序列号 (客户端提供,服务端原样返回) ClientMsgNo string // 客户端消息编号(目前只有mos协议有效) ReasonCode ReasonCode // 原因代码 }
SendackPacket 发送回执包
func (*SendackPacket) GetPacketType ¶
func (s *SendackPacket) GetPacketType() PacketType
GetPacketType 包类型
func (*SendackPacket) String ¶
func (s *SendackPacket) String() string