common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ControlLogin = iota
	ControlRegister
	ControlData
	ControlHeart
	ControlError
	ControlClosed
)
View Source
const (
	ProtocolTopic = iota //byte
	ProtocolRPC
)
View Source
const (
	ClientStaConnect = iota //connect
	ClientStaLogin
	ClientStaRegister
	ClientStaData
	ClientStaClose
)
View Source
const (
	PluginUnStart = iota
	PluginStarting
	PluginRun
	PluginStop
	PluginErr
)
View Source
const HeadCRC8Len uint32 = 1

Variables

This section is empty.

Functions

func GetCrc8

func GetCrc8(buf []byte) (crc byte)

反序异或 x^8+x^5+x^4+x^0

func TopMsgPack

func TopMsgPack(msg *TopMessage) ([]byte, error)

Pack 封包方法(压缩数据)

Types

type DataPack

type DataPack struct{}

DataPack 封包拆包类实例,暂时不需要成员

func (*DataPack) GetHeadLen

func (dp *DataPack) GetHeadLen() uint32

GetHeadLen 获取包头长度方法

func (*DataPack) Pack

func (dp *DataPack) Pack(msg IMessage) ([]byte, error)

Pack 封包方法(压缩数据)

func (*DataPack) Unpack

func (dp *DataPack) Unpack(binaryData []byte) (IMessage, error)

Unpack 拆包方法(解压数据)

type ErrConnectionFailed

type ErrConnectionFailed error

Error reported when connection to the external plugin has failed.

type ErrHttpServe

type ErrHttpServe error

Error reported when the external plugin cannot start listening for calls.

type ErrInvalidMessage

type ErrInvalidMessage error

Error reported when an invalid message is printed by the external plugin.

type ErrRegistrationTimeout

type ErrRegistrationTimeout error

Error reported when the plugin fails to register before the registration timeout expires.

type IMessage

type IMessage interface {
	GetMsgID() uint32       //获取消息ID
	GetData() []byte        //获取消息内容
	GetDataLen() uint32     //设置消息数据段长度
	GetHeadCRC([]byte) byte //数据帧头
	GetDataCRC() uint32     //数据内容数据校验
	GetCRCLen() uint32
	CheckDataCRC([]byte) bool
	GetVer() byte
	GetProtocol() byte
	GetControl() byte

	SetMsgID(uint32)   //设计消息ID
	SetData([]byte)    //设计消息内容
	SetDataLen(uint32) //设置消息数据段长度
}

func NewMsgPackage

func NewMsgPackage(ID uint32, ctr byte, data []byte) IMessage

NewMsgPackage 创建一个Message消息包

func NewMsgPackageWithProtocol

func NewMsgPackageWithProtocol(ID uint32, ctr byte, Protocol byte, data []byte) IMessage

type LoginCfg

type LoginCfg struct {
	Name   string `p:"name" json:"name"`     //名称
	Passwd string `p:"passwd" json:"passwd"` //名
	Id     uint32 `p:"id" json:"id"`         //id
}

type Message

type Message struct {
	DataLen  uint32 //消息的长度
	ID       uint32 //消息的ID
	Version  byte   //版本号
	Protocol byte   //协议类型
	Control  byte   //控制
	HeadCRC  byte   //头验证
	Data     []byte //消息的内容
	DataCRC  uint32
}

Message 消息

func (*Message) CheckDataCRC

func (msg *Message) CheckDataCRC([]byte) bool

func (*Message) GetCRCLen

func (msg *Message) GetCRCLen() uint32

func (*Message) GetControl

func (msg *Message) GetControl() byte

func (*Message) GetData

func (msg *Message) GetData() []byte

GetData 获取消息内容

func (*Message) GetDataCRC

func (msg *Message) GetDataCRC() uint32

func (*Message) GetDataLen

func (msg *Message) GetDataLen() uint32

GetDataLen 获取消息数据段长度

func (*Message) GetHeadCRC

func (msg *Message) GetHeadCRC(data []byte) byte

func (*Message) GetMsgID

func (msg *Message) GetMsgID() uint32

GetMsgID 获取消息ID

func (*Message) GetProtocol

func (msg *Message) GetProtocol() byte

func (*Message) GetVer

func (msg *Message) GetVer() byte

func (*Message) SetData

func (msg *Message) SetData(data []byte)

SetData 设计消息内容

func (*Message) SetDataLen

func (msg *Message) SetDataLen(len uint32)

SetDataLen 设置消息数据段长度

func (*Message) SetMsgID

func (msg *Message) SetMsgID(msgID uint32)

SetMsgID 设计消息ID

type Packet

type Packet interface {
	Unpack(binaryData []byte) (IMessage, error)
	Pack(msg IMessage) ([]byte, error)
	GetHeadLen() uint32
}

func NewDataPack

func NewDataPack() Packet

NewDataPack 封包拆包实例初始化方法

type PluginApp

type PluginApp interface {
	Open(ctx context.Context, f func(filter, client string, qos byte) bool) error
	Start(cfg *PluginCfg, ctx context.Context) error
	Close(ctx context.Context) error
	Update(ctx context.Context) error
}

type PluginCfg

type PluginCfg struct {
	Proto      string `p:"proto" json:"proto"`           //参数名称
	Unixdir    string `p:"unixdir" json:"unixdir"`       //unix文件地址
	ServerAddr string `p:"serveraddr" json:"serveraddr"` //服务器地址
	Name       string `p:"name" json:"name"`             //名称
	Passwd     string `p:"passwd" json:"passwd"`         //名称
	Params     string `p:"params" json:"params"`         //参数
}

type RegisterCfg

type RegisterCfg struct {
	Name  string `p:"name" json:"name"`   //名称
	Id    uint32 `p:"id" json:"id"`       //id
	Topic string `p:"topic" json:"topic"` //订阅的topic
	Qos   byte   `p:"topic" json:"qos"`   //等级
}

type ServiceMsg

type ServiceMsg struct {
}

type TopMessage

type TopMessage struct {
	TopicName []byte
	TopicLen  uint16
	Data      []byte
	DataLen   uint32
	Retain    byte
	Qos       byte
}

func TopMsgUnpack

func TopMsgUnpack(binaryData []byte) (*TopMessage, error)

Unpack 拆包方法(解压数据)

type TopicInfo

type TopicInfo struct {
	TopicName string
	Retain    bool
	Qos       byte
}

type TopicMap

type TopicMap map[string]TopicInfo

Jump to

Keyboard shortcuts

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