Ai
3 Star 41 Fork 40

coco/go808

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
property.go 1023 Bytes
一键复制 编辑 原始数据 按行查看 历史
anchor 提交于 2021-05-28 17:18 +08:00 . 更新包名
package protocol
import (
"gitee.com/coco/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/coco/go808.git
git@gitee.com:coco/go808.git
coco
go808
go808
5c885155315d

搜索帮助