1 Star 0 Fork 40

peng2289/go808

forked from coco/go808 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
property.go 1022 Bytes
一键复制 编辑 原始数据 按行查看 历史
peng2289 提交于 2023-03-03 13:45 +08:00 . 更换包名
package protocol
import (
"gitee.com/oco/go808/errors"
)
// 消息体属性
type Property uint16
// 启用分包
func (property *Property) enablePacket() {
val := uint16(*property)
*property = Property(val | (1 << 13))
}
// 启用加密
func (property *Property) enableEncrypt() {
val := uint16(*property)
*property = Property(val | (1 << 10))
}
// 是否分包
func (property Property) IsEnablePacket() bool {
val := uint16(property)
return val&(1<<13) > 0
}
// 是否加密
func (property Property) IsEnableEncrypt() bool {
val := uint16(property)
return val&(1<<10) > 0
}
// 获取消息体长度
func (property *Property) GetBodySize() uint16 {
// 前十位表示消息体长度
// 0x3ff == ‭001111111111‬
val := uint16(*property)
return ((val << 6) >> 6) & 0x3ff
}
// 设置消息体长度
func (property *Property) SetBodySize(size uint16) error {
if size > 0x3ff {
return errors.ErrBodyTooLong
}
val := uint16(*property)
*property = Property(((val >> 10) << 10) | size)
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/oco/go808.git
git@gitee.com:oco/go808.git
oco
go808
go808
32b1471f79b9

搜索帮助