Documentation ¶
Index ¶
- Constants
- func ToFixHeaderUint8(f Frame) uint8
- 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 Action
- type Channel
- 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 EncodeOption
- type EncodeOptions
- type Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) End()
- 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 FrameType
- type Framer
- func (f Framer) GetDUP() bool
- func (f Framer) GetFrameSize() int64
- func (f Framer) GetFrameType() FrameType
- func (f Framer) GetHasServerVersion() bool
- func (f Framer) GetNoPersist() bool
- func (f Framer) GetRedDot() bool
- func (f Framer) GetRemainingLength() uint32
- func (f Framer) GetsyncOnce() bool
- func (f Framer) String() string
- type PacketDecodeFunc
- type PacketEncodeFunc
- type PingPacket
- type PongPacket
- type Protocol
- type ReasonCode
- type RecvPacket
- type RecvackPacket
- type SendPacket
- type SendackPacket
- type Setting
- type StreamFlag
- type SubPacket
- type SubackPacket
- type WKProto
Constants ¶
View Source
const ( // APP APP APP DeviceFlag = iota // WEB WEB WEB = 1 // PC PC PC = 2 // SYSTEM 系统 SYSTEM = 99 )
View Source
const ( SettingByteSize = 1 // setting固定大小 StringFixLenByteSize = 2 // 字符串可变大小 ClientSeqByteSize = 4 // clientSeq的大小 ChannelTypeByteSize = 1 // channelType的大小 VersionByteSize = 1 // version的大小 DeviceFlagByteSize = 1 ClientTimestampByteSize = 8 TimeDiffByteSize = 8 ReasonCodeByteSize = 1 MessageIDByteSize = 8 MessageSeqByteSize = 4 TimestampByteSize = 4 ActionByteSize = 1 StreamSeqByteSize = 4 StreamFlagByteSize = 1 ExpireByteSize = 4 )
View Source
const ( // ChannelTypePerson 个人频道 ChannelTypePerson uint8 = 1 // ChannelTypeGroup 群频道 ChannelTypeGroup uint8 = 2 // 群组频道 ChannelTypeCustomerService uint8 = 3 // 客服频道 ChannelTypeCommunity uint8 = 4 // 社区频道 ChannelTypeCommunityTopic uint8 = 5 // 社区话题频道 ChannelTypeInfo uint8 = 6 // 资讯频道(有临时订阅者的概念,查看资讯的时候加入临时订阅,退出资讯的时候退出临时订阅) ChannelTypeData uint8 = 7 // 数据频道 )
View Source
const LatestVersion = 3
LatestVersion 最新版本
View Source
const MaxRemaingLength uint32 = 1024 * 1024
MaxRemaingLength 最大剩余长度 // 1<<28 - 1
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnackPacket ¶
type ConnackPacket struct { Framer ServerVersion uint8 // 服务端版本 ServerKey string // 服务端的DH公钥 Salt string // salt TimeDiff int64 // 客户端时间与服务器的差值,单位毫秒。 ReasonCode ReasonCode // 原因码 }
ConnackPacket 连接回执包
func (ConnackPacket) GetFrameType ¶
func (c ConnackPacket) GetFrameType() FrameType
GetFrameType 获取包类型
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) GetFrameType ¶
func (c ConnectPacket) GetFrameType() FrameType
GetFrameType 包类型
func (ConnectPacket) String ¶
func (c ConnectPacket) String() string
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 )
func (DeviceLevel) String ¶
func (r DeviceLevel) String() string
type DisconnectPacket ¶
type DisconnectPacket struct { Framer ReasonCode ReasonCode // 断开原因代号 Reason string // 断开原因 }
DisconnectPacket 断开连接数据包
func (DisconnectPacket) GetFrameType ¶
func (c DisconnectPacket) GetFrameType() FrameType
GetFrameType 包类型
func (DisconnectPacket) String ¶
func (c DisconnectPacket) String() string
type EncodeOption ¶ added in v1.0.2
type EncodeOption func(*EncodeOptions)
func EcodeWithCap ¶ added in v1.0.2
func EcodeWithCap(cap int) EncodeOption
type EncodeOptions ¶ added in v1.0.2
type EncodeOptions struct {
Cap int
}
func NewEncodeOptions ¶ added in v1.0.2
func NewEncodeOptions() *EncodeOptions
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder 编码者
func (*Encoder) WriteStringAll ¶
WriteStringAll WriteStringAll
type Frame ¶
type Frame interface { GetFrameType() FrameType GetRemainingLength() uint32 // GetPersist 是否存储 GetNoPersist() bool // GetRedDot 是否显示红点 GetRedDot() bool // GetsyncOnce 是否只被同步一次 GetsyncOnce() bool // 是否是重发的消息 GetDUP() bool GetFrameSize() int64 // 总个frame的大小(不参与编码解码) GetHasServerVersion() bool // 是否有服务端版本 connack包用到 }
Frame 接口
type FrameType ¶
type FrameType uint8
func SettingFromUint8(v uint8) Setting { s := Setting{} s.Receipt = (v >> 7 & 0x01) > 0 return s }
FrameType 包类型
type Framer ¶
type Framer struct { FrameType FrameType RemainingLength uint32 // 控制报文总长度等于固定报头的长度加上剩余长度 NoPersist bool // 是否不持久化 RedDot bool // 是否显示红点 SyncOnce bool // 此消息只被同步或被消费一次 DUP bool // 是否是重发消息 HasServerVersion bool // 是否有服务端版本 connack包用到 FrameSize int64 }
Framer 包的基础framer
func (Framer) GetFrameSize ¶
func (Framer) GetHasServerVersion ¶ added in v1.0.1
func (Framer) GetRemainingLength ¶
GetRemainingLength 包剩余长度
type PacketDecodeFunc ¶
PacketDecodeFunc 包解码函数
type PacketEncodeFunc ¶
PacketEncodeFunc 包编码函数
type Protocol ¶
type Protocol interface { // DecodeFrame 解码消息 返回frame 和 数据大小 和 error DecodeFrame(data []byte, version uint8) (Frame, int, error) // EncodeFrame 编码消息 EncodeFrame(packet Frame, version uint8) ([]byte, error) }
Protocol Protocol
type ReasonCode ¶
type ReasonCode uint8
ReasonCode 原因码
const ( // ReasonUnknown 未知错误 ReasonUnknown 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 // ReasonConnectKick 连接被踢 ReasonConnectKick // ReasonNotInWhitelist 没在白名单内 ReasonNotInWhitelist // 查询用户token错误 ReasonQueryTokenError // 系统错误 ReasonSystemError // 错误的频道ID ReasonChannelIDError // ReasonNodeMatchError 节点匹配错误 ReasonNodeMatchError // ReasonNodeNotMatch 节点不匹配 ReasonNodeNotMatch ReasonBan // 频道被封禁 ReasonNotSupportHeader // 不支持的header ReasonClientKeyIsEmpty // clientKey 是空的 ReasonRateLimit // 速率限制 ReasonNotSupportChannelType // 不支持的频道类型 ReasonDisband // 频道已解散 )
func (ReasonCode) String ¶
func (r ReasonCode) String() string
type RecvPacket ¶
type RecvPacket struct { Framer Setting Setting MsgKey string // 用于验证此消息是否合法(仿中间人篡改) Expire uint32 // 消息过期时间 0 表示永不过期 MessageID int64 // 服务端的消息ID(全局唯一) MessageSeq uint32 // 消息序列号 (用户唯一,有序递增) ClientMsgNo string // 客户端唯一标示 StreamNo string // 流式编号 StreamSeq uint32 // 流式序列号 StreamFlag StreamFlag // 流式标记 Timestamp int32 // 服务器消息时间戳(10位,到秒) ChannelID string // 频道ID ChannelType uint8 // 频道类型 Topic string // 话题ID FromUID string // 发送者UID Payload []byte // 消息内容 // ---------- 以下不参与编码 ------------ ClientSeq uint64 // 客户端提供的序列号,在客户端内唯一 }
RecvPacket 收到消息的包
func (*RecvPacket) Size ¶ added in v1.0.2
func (r *RecvPacket) Size() int
func (*RecvPacket) SizeWithProtoVersion ¶ added in v1.0.2
func (r *RecvPacket) SizeWithProtoVersion(protVersion uint8) int
func (*RecvPacket) String ¶
func (r *RecvPacket) String() string
type RecvackPacket ¶
RecvackPacket 对收取包回执
func (*RecvackPacket) GetFrameType ¶
func (s *RecvackPacket) GetFrameType() FrameType
GetPacketType 包类型
func (*RecvackPacket) String ¶
func (s *RecvackPacket) String() string
type SendPacket ¶
type SendPacket struct { Framer Setting Setting MsgKey string // 用于验证此消息是否合法(仿中间人篡改) Expire uint32 // 消息过期时间 0 表示永不过期 ClientSeq uint64 // 客户端提供的序列号,在客户端内唯一 ClientMsgNo string // 客户端消息唯一编号一般是uuid,为了去重 StreamNo string // 流式编号 ChannelID string // 频道ID(如果是个人频道ChannelId为个人的UID) ChannelType uint8 // 频道类型(1.个人 2.群组) Topic string // 消息topic Payload []byte // 消息内容 }
SendPacket 发送包
func (*SendPacket) String ¶
func (s *SendPacket) String() string
func (*SendPacket) UniqueKey ¶
func (s *SendPacket) UniqueKey() string
type SendackPacket ¶
type SendackPacket struct { Framer MessageID int64 // 消息ID(全局唯一) MessageSeq uint32 // 消息序列号(用户唯一,有序) ClientSeq uint64 // 客户端序列号 (客户端提供,服务端原样返回) ClientMsgNo string // 客户端消息编号(目前只有mos协议有效) ReasonCode ReasonCode // 原因代码 }
SendackPacket 发送回执包
func (*SendackPacket) GetFrameType ¶
func (s *SendackPacket) GetFrameType() FrameType
GetPacketType 包类型
func (*SendackPacket) String ¶
func (s *SendackPacket) String() string
type StreamFlag ¶
type StreamFlag uint8
const ( StreamFlagStart StreamFlag = 0 // 开始 StreamFlagIng StreamFlag = 1 // 进行中 StreamFlagEnd StreamFlag = 2 // 结束 )
type SubPacket ¶
type SubackPacket ¶
type SubackPacket struct { Framer SubNo string // 订阅编号 ChannelID string // 频道ID(如果是个人频道ChannelId为个人的UID) ChannelType uint8 // 频道类型 Action Action // 动作 ReasonCode ReasonCode // 原因码 }
func (*SubackPacket) GetFrameType ¶
func (s *SubackPacket) GetFrameType() FrameType
GetPacketType 包类型
type WKProto ¶
WKroto 悟空IM协议对象
func (*WKProto) DecodeFrame ¶
DecodePacket 解码包
func (*WKProto) DecodePacketWithConn ¶
DecodePacketWithConn 解码包
Click to show internal directories.
Click to hide internal directories.