This commit is contained in:
@@ -56,9 +56,7 @@ type DoubleUInt8Struct struct {
|
||||
}
|
||||
|
||||
func (di *DoubleUInt8) Pack(p []byte, opt *Options) (int, error) {
|
||||
for i, value := range *di {
|
||||
p[i] = value
|
||||
}
|
||||
copy(p, (*di)[:])
|
||||
|
||||
return 2, nil
|
||||
}
|
||||
@@ -131,9 +129,7 @@ type SliceUInt8Struct struct {
|
||||
}
|
||||
|
||||
func (ia *SliceUInt8) Pack(p []byte, opt *Options) (int, error) {
|
||||
for i, value := range *ia {
|
||||
p[i] = value
|
||||
}
|
||||
copy(p, *ia)
|
||||
|
||||
return len(*ia) + 1, nil
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func (f *Field) Size(val reflect.Value, options *Options) int {
|
||||
var defaultOrder = binary.BigEndian
|
||||
|
||||
// packVal 优化版:减少反射开销+优化内存拷贝+优雅错误处理
|
||||
func (f *Field) packVal(buf []byte, val reflect.Value, length int, options *Options) (size int, err error) {
|
||||
func (f *Field) packVal(buf []byte, val reflect.Value, _ int, options *Options) (size int, err error) {
|
||||
// 1. 预缓存order,避免重复判断
|
||||
order := f.Order
|
||||
if options != nil && options.Order != nil {
|
||||
@@ -252,7 +252,6 @@ func (f *Field) Pack(buf []byte, val reflect.Value, length int, options *Options
|
||||
copy(buf, buf[:length])
|
||||
return length, nil
|
||||
}
|
||||
return val.Len(), nil
|
||||
}
|
||||
pos := 0
|
||||
var zero reflect.Value
|
||||
@@ -276,7 +275,7 @@ func (f *Field) Pack(buf []byte, val reflect.Value, length int, options *Options
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Field) unpackVal(buf []byte, val reflect.Value, length int, options *Options) error {
|
||||
func (f *Field) unpackVal(buf []byte, val reflect.Value, _ int, options *Options) error {
|
||||
order := f.Order
|
||||
if options.Order != nil {
|
||||
order = options.Order
|
||||
|
||||
Reference in New Issue
Block a user