From 58afc9df1f378c5befde47e4496287fe95e026ca Mon Sep 17 00:00:00 2001 From: CPunch Date: Sat, 2 Dec 2023 21:54:54 -0600 Subject: [PATCH] protocol/packet: use append() w/ temp buf to grow --- cnet/protocol/packet.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cnet/protocol/packet.go b/cnet/protocol/packet.go index 21207ca..ab15932 100644 --- a/cnet/protocol/packet.go +++ b/cnet/protocol/packet.go @@ -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 } }