1 Star 0 Fork 36

HonglinRen / go808

forked from coco / go808 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
t808_0x8001.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2020-04-08 21:04 . 添加RSA加密
package protocol
// 平台通用应答
type T808_0x8001 struct {
// 对应的终端消息的流水号
ReplyMsgSerialNo uint16
// 对应的终端消息的ID
ReplyMsgID MsgID
// 处理结果
Result Result
}
func (entity *T808_0x8001) MsgID() MsgID {
return MsgT808_0x8001
}
func (entity *T808_0x8001) Encode() ([]byte, error) {
writer := NewWriter()
// 写入流水号
writer.WriteUint16(entity.ReplyMsgSerialNo)
// 写入消息ID
writer.WriteUint16(uint16(entity.ReplyMsgID))
// 写入处理结果
writer.WriteByte(byte(entity.Result))
return writer.Bytes(), nil
}
func (entity *T808_0x8001) Decode(data []byte) (int, error) {
if len(data) < 5 {
return 0, ErrInvalidBody
}
reader := NewReader(data)
// 读取流水号
msgSerialNo, err := reader.ReadUint16()
if err != nil {
return 0, err
}
// 读取消息ID
msgID, err := reader.ReadUint16()
if err != nil {
return 0, err
}
// 读取处理结果
b, err := reader.ReadByte()
if err != nil {
return 0, err
}
entity.ReplyMsgID = MsgID(msgID)
entity.Result = Result(b)
entity.ReplyMsgSerialNo = msgSerialNo
return len(data) - reader.Len(), nil
}
Go
1
https://gitee.com/honlin_ren/go808.git
git@gitee.com:honlin_ren/go808.git
honlin_ren
go808
go808
20b7a9eb4995

搜索帮助