mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 15:00:07 +00:00
protocol/packet: use append() w/ temp buf to grow
This commit is contained in:
parent
e257bf998f
commit
58afc9df1f
@ -42,10 +42,7 @@ func (pkt Packet) encodeStructField(field reflect.StructField, value reflect.Val
|
|||||||
buf16 = buf16[:sz]
|
buf16 = buf16[:sz]
|
||||||
} else {
|
} else {
|
||||||
// grow
|
// grow
|
||||||
// TODO: probably a better way to do this?
|
buf16 = append(buf16, make([]uint16, sz-len(buf16))...)
|
||||||
for len(buf16) < sz {
|
|
||||||
buf16 = append(buf16, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@ -125,8 +122,7 @@ func (pkt Packet) decodeStructField(field reflect.StructField, value reflect.Val
|
|||||||
// consume padding bytes
|
// consume padding bytes
|
||||||
pad, err := strconv.Atoi(field.Tag.Get("pad"))
|
pad, err := strconv.Atoi(field.Tag.Get("pad"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dummy := make([]byte, pad)
|
if _, err := pkt.readWriter.Read(make([]byte, pad)); err != nil {
|
||||||
if _, err := pkt.readWriter.Read(dummy); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user