lmproto

package
v0.0.0-...-325de3d Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// APP APP
	APP DeviceFlag = iota
	// WEB WEB
	WEB = 1
	// SYSTEM 系统
	SYSTEM = 2
)
View Source
const LatestVersion = 4

LatestVersion 最新版本

View Source
const MaxRemaingLength uint32 = 1024 * 1024

MaxRemaingLength 最大剩余长度 // 1<<28 - 1

Variables

This section is empty.

Functions

func Binary

func Binary(reader io.Reader) ([]byte, error)

Binary Binary

func Int16

func Int16(reader io.Reader) (int16, error)

Int16 Int16

func Int32

func Int32(reader io.Reader) (int32, error)

Int32 Int32

func ToFixHeaderUint8

func ToFixHeaderUint8(f Frame) uint8

ToFixHeaderUint8 ToFixHeaderUint8

func Uint32

func Uint32(reader io.Reader) (uint32, error)

Uint32 Uint32

func WriteBinary

func WriteBinary(b []byte, w io.Writer) error

WriteBinary WriteBinary

func WriteInt16

func WriteInt16(i int, w io.Writer) error

WriteInt16 WriteInt16

func WriteUint32

func WriteUint32(v uint32, w io.Writer) error

WriteUint32 WriteUint32

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 Decoder

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

Decoder 解码

func NewDecoder

func NewDecoder(p []byte) *Decoder

NewDecoder NewDecoder

func (*Decoder) Binary

func (d *Decoder) Binary() ([]byte, error)

Binary Binary

func (*Decoder) BinaryAll

func (d *Decoder) BinaryAll() ([]byte, error)

BinaryAll BinaryAll

func (*Decoder) Bytes

func (d *Decoder) Bytes(num int) ([]byte, error)

Bytes Bytes

func (*Decoder) Int16

func (d *Decoder) Int16() (int16, error)

Int16 Int16

func (*Decoder) Int32

func (d *Decoder) Int32() (int32, error)

Int32 Int32

func (*Decoder) Int64

func (d *Decoder) Int64() (int64, error)

Int64 Int64

func (*Decoder) Len

func (d *Decoder) Len() int

Len 长度

func (*Decoder) String

func (d *Decoder) String() (string, error)

func (*Decoder) StringAll

func (d *Decoder) StringAll() (string, error)

StringAll StringAll

func (*Decoder) Uint16

func (d *Decoder) Uint16() (uint16, error)

Uint16 Uint16

func (*Decoder) Uint32

func (d *Decoder) Uint32() (uint32, error)

Uint32 Uint32

func (*Decoder) Uint64

func (d *Decoder) Uint64() (uint64, error)

Uint64 Uint64

func (*Decoder) Uint8

func (d *Decoder) Uint8() (uint8, error)

Uint8 Uint8

func (*Decoder) Variable

func (d *Decoder) Variable() (uint64, error)

Variable Variable

type DeviceFlag

type DeviceFlag uint8

DeviceFlag 设备类型

func (DeviceFlag) String

func (r DeviceFlag) String() string

func (DeviceFlag) ToUint8

func (r DeviceFlag) ToUint8() uint8

ToUint8 转换为uint8

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 NewEncoder

func NewEncoder() *Encoder

NewEncoder NewEncoder

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

Bytes Bytes

func (*Encoder) Len

func (e *Encoder) Len() int

Len Len

func (*Encoder) WriteBinary

func (e *Encoder) WriteBinary(b []byte)

WriteBinary WriteBinary

func (*Encoder) WriteByte

func (e *Encoder) WriteByte(b byte) error

WriteByte WriteByte

func (*Encoder) WriteBytes

func (e *Encoder) WriteBytes(b []byte)

WriteBytes WriteBytes

func (*Encoder) WriteInt

func (e *Encoder) WriteInt(i int) error

WriteInt WriteInt

func (*Encoder) WriteInt16

func (e *Encoder) WriteInt16(i int)

WriteInt16 WriteInt16

func (*Encoder) WriteInt32

func (e *Encoder) WriteInt32(i int32)

WriteInt32 WriteInt32

func (*Encoder) WriteInt64

func (e *Encoder) WriteInt64(i int64)

WriteInt64 WriteInt64

func (*Encoder) WriteString

func (e *Encoder) WriteString(str string)

WriteString WriteString

func (*Encoder) WriteStringAll

func (e *Encoder) WriteStringAll(str string)

WriteStringAll WriteStringAll

func (*Encoder) WriteUint16

func (e *Encoder) WriteUint16(i uint16)

WriteUint16 WriteUint16

func (*Encoder) WriteUint32

func (e *Encoder) WriteUint32(i uint32)

WriteUint32 WriteUint32

func (*Encoder) WriteUint64

func (e *Encoder) WriteUint64(i uint64)

WriteUint64 WriteUint64

func (*Encoder) WriteUint8

func (e *Encoder) WriteUint8(i uint8)

WriteUint8 WriteUint8

func (*Encoder) WriteVariable

func (e *Encoder) WriteVariable(v int)

WriteVariable WriteVariable

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 FramerFromUint8

func FramerFromUint8(v uint8) Framer

FramerFromUint8 FramerFromUint8

func (Framer) GetDUP

func (f Framer) GetDUP() bool

GetDUP 是否是重发消息

func (Framer) GetNoPersist

func (f Framer) GetNoPersist() bool

GetNoPersist 是否不持久化

func (Framer) GetPacketType

func (f Framer) GetPacketType() PacketType

GetPacketType GetPacketType

func (Framer) GetRedDot

func (f Framer) GetRedDot() bool

GetRedDot 是否显示红点

func (Framer) GetRemainingLength

func (f Framer) GetRemainingLength() uint32

GetRemainingLength 包剩余长度

func (Framer) GetsyncOnce

func (f Framer) GetsyncOnce() bool

GetsyncOnce 是否只被同步一次

func (Framer) String

func (f Framer) String() string

type LiMaoProto

type LiMaoProto struct {
	limlog.Log
}

LiMaoProto 狸猫协议对象

func New

func New() *LiMaoProto

New 创建limao协议对象

func (*LiMaoProto) DecodePacket

func (l *LiMaoProto) DecodePacket(data []byte, version uint8) (Frame, int, error)

DecodePacket 解码包

func (*LiMaoProto) DecodePacketWithConn

func (l *LiMaoProto) DecodePacketWithConn(conn io.Reader, version uint8) (Frame, error)

DecodePacketWithConn 解码包

func (*LiMaoProto) EncodePacket

func (l *LiMaoProto) EncodePacket(packet interface{}, version uint8) ([]byte, error)

EncodePacket 编码包

type PacketDecodeFunc

type PacketDecodeFunc func(frame Frame, remainingBytes []byte, version uint8) (Frame, error)

PacketDecodeFunc 包解码函数

type PacketEncodeFunc

type PacketEncodeFunc func(frame Frame, version uint8) ([]byte, error)

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) Byte

func (r ReasonCode) Byte() byte

Byte 转换为byte

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

func (*RecvPacket) VerityString

func (r *RecvPacket) VerityString() string

VerityString 验证字符串

type RecvackPacket

type RecvackPacket struct {
	Framer
	MessageID  int64  // 服务端的消息ID(全局唯一)
	MessageSeq uint32 // 消息序列号
}

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

func (*SendPacket) VerityString

func (s *SendPacket) VerityString() string

VerityString 验证字符串

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

type Setting

type Setting struct {
	Receipt bool // 消息已读回执,此标记表示,此消息需要已读回执
}

func SettingFromUint8

func SettingFromUint8(v uint8) Setting

func (Setting) ToUint8

func (s Setting) ToUint8() uint8

Jump to

Keyboard shortcuts

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