1 Star 0 Fork 36

peng2289 / go808

forked from coco / go808 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
0x12.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
peng2289 提交于 2023-03-03 13:45 . 更换包名
package extra
import (
"bytes"
"encoding/binary"
"gitee.com/oco/go808/errors"
)
// 进出报警
type Extra_0x12 struct {
serialized []byte
value Extra_0x12_Value
}
type Extra_0x12_Value struct {
Type byte
AreaID uint32
Direction byte
}
func NewExtra_0x12(value Extra_0x12_Value) *Extra_0x12 {
extra := Extra_0x12{
value: value,
}
var temp [4]byte
buffer := bytes.NewBuffer(nil)
buffer.WriteByte(value.Type)
binary.BigEndian.PutUint32(temp[:], value.AreaID)
buffer.Write(temp[:])
buffer.WriteByte(value.Direction)
extra.serialized = buffer.Bytes()
return &extra
}
func (Extra_0x12) ID() byte {
return byte(TypeExtra_0x12)
}
func (extra Extra_0x12) Data() []byte {
return extra.serialized
}
func (extra Extra_0x12) Value() interface{} {
return extra.value
}
func (extra *Extra_0x12) Decode(data []byte) (int, error) {
if len(data) < 6 {
return 0, errors.ErrInvalidExtraLength
}
extra.value.Type = data[0]
extra.value.AreaID = binary.BigEndian.Uint32(data[1:5])
extra.value.Direction = data[5]
return 6, nil
}
Go
1
https://gitee.com/oco/go808.git
git@gitee.com:oco/go808.git
oco
go808
go808
32b1471f79b9

搜索帮助