refactor(rpc): 更新结构体标签以跳过特定字段序列化 将多个结构体中的 `struc:"[0]pad"` 标签更改为 `struc:"skip"`, 以避免在序列化过程中处理不必要的填充字段。同时新增放生与领回相关逻辑, 并完善部分控制器函数和消息结构定义。 ```
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package task
|
||
|
||
import (
|
||
"blazing/logic/service/common"
|
||
"encoding/binary"
|
||
"errors"
|
||
|
||
"github.com/pointernil/bitset32"
|
||
)
|
||
|
||
type GetTaskBufInboundInfo struct {
|
||
Head common.TomeeHeader `cmd:"2203|2234" struc:"skip"`
|
||
|
||
TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,
|
||
}
|
||
type GetTaskBufOutboundInfo struct {
|
||
TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,
|
||
Flag uint32 `json:"flag" description:"暂时未知"` // 暂时未知,
|
||
TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息,
|
||
}
|
||
|
||
// 获得任务数组
|
||
func (t *GetTaskBufOutboundInfo) GetList() *bitset32.BitSet32 {
|
||
|
||
return bitset32.From(t.TaskList)
|
||
}
|
||
|
||
// BytesToInt32Slice 将[]byte转换为[]int32
|
||
// 注意:src长度必须是4的倍数,因为每个int32由4字节组成
|
||
// order参数指定字节序(binary.BigEndian 或 binary.LittleEndian)
|
||
func BytesToInt32Slice(src []byte, order binary.ByteOrder) ([]int32, error) {
|
||
// 检查输入长度是否为4的倍数
|
||
if len(src)%4 != 0 {
|
||
return nil, errors.New("输入字节切片长度必须是4的倍数")
|
||
}
|
||
|
||
// 计算目标切片长度
|
||
dstLen := len(src) / 4
|
||
dst := make([]int32, dstLen)
|
||
|
||
// 逐个转换4字节为int32
|
||
for i := 0; i < dstLen; i++ {
|
||
// 计算当前位置的字节偏移
|
||
offset := i * 4
|
||
// 读取4字节并转换为uint32,再转换为int32
|
||
dst[i] = int32(order.Uint32(src[offset : offset+4]))
|
||
}
|
||
|
||
return dst, nil
|
||
}
|
||
|
||
// Int32SliceToBytes 将[]int32转换回[]byte
|
||
// order参数指定字节序(binary.BigEndian 或 binary.LittleEndian)
|
||
func Int32SliceToBytes(src []int32, order binary.ByteOrder) []byte {
|
||
// 计算目标字节切片长度
|
||
dst := make([]byte, len(src)*4)
|
||
|
||
// 逐个将int32转换为4字节
|
||
for i, v := range src {
|
||
// 计算当前位置的字节偏移
|
||
offset := i * 4
|
||
// 将int32转换为uint32,再写入字节切片
|
||
order.PutUint32(dst[offset:offset+4], uint32(v))
|
||
}
|
||
|
||
return dst
|
||
}
|