3 Star 38 Fork 36

coco / go808

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
0x11.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
anchor 提交于 2021-05-28 17:18 . 更新包名
package extra
import (
"bytes"
"encoding/binary"
"gitee.com/coco/go808/errors"
)
// 超速报警
type Extra_0x11 struct {
serialized []byte
value Extra_0x11_Value
}
type Extra_0x11_Value struct {
Type byte
AreaID *uint32
}
func NewExtra_0x11(value Extra_0x11_Value) *Extra_0x11 {
extra := Extra_0x11{
value: value,
}
buffer := bytes.NewBuffer(nil)
buffer.WriteByte(value.Type)
if value.Type != 0 && value.AreaID != nil {
var temp [4]byte
binary.BigEndian.PutUint32(temp[:], uint32(*value.AreaID))
buffer.Write(temp[:])
}
extra.serialized = buffer.Bytes()
return &extra
}
func (Extra_0x11) ID() byte {
return byte(TypeExtra_0x11)
}
func (extra Extra_0x11) Data() []byte {
return extra.serialized
}
func (extra Extra_0x11) Value() interface{} {
return extra.value
}
func (extra *Extra_0x11) Decode(data []byte) (int, error) {
if len(data) < 1 {
return 0, errors.ErrInvalidExtraLength
}
extra.value.AreaID = nil
extra.value.Type = data[0]
if extra.value.Type == 0 {
return 1, nil
}
if len(data[1:]) < 4 {
return 0, errors.ErrInvalidExtraLength
}
areaID := binary.BigEndian.Uint32(data[1:])
extra.value.AreaID = &areaID
return 5, nil
}
Go
1
https://gitee.com/coco/go808.git
git@gitee.com:coco/go808.git
coco
go808
go808
5c885155315d

搜索帮助