mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-21 06:50:06 +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]
|
||||
} else {
|
||||
// grow
|
||||
// TODO: probably a better way to do this?
|
||||
for len(buf16) < sz {
|
||||
buf16 = append(buf16, 0)
|
||||
}
|
||||
buf16 = append(buf16, make([]uint16, sz-len(buf16))...)
|
||||
}
|
||||
|
||||
// write
|
||||
@ -125,8 +122,7 @@ func (pkt Packet) decodeStructField(field reflect.StructField, value reflect.Val
|
||||
// consume padding bytes
|
||||
pad, err := strconv.Atoi(field.Tag.Get("pad"))
|
||||
if err == nil {
|
||||
dummy := make([]byte, pad)
|
||||
if _, err := pkt.readWriter.Read(dummy); err != nil {
|
||||
if _, err := pkt.readWriter.Read(make([]byte, pad)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user