From 8042a498fe4c66d7e2d56eb44b792b7fb9428d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Fri, 26 Aug 2022 10:29:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/device.go b/device.go index 56778a3..1188b0d 100644 --- a/device.go +++ b/device.go @@ -76,16 +76,17 @@ func (cli *RPCClient) run() { buf.Reset() + // encode gob + enc := gob.NewEncoder(buf) + cliBuffer := <-cli.FrameChan + enc.Encode(cliBuffer.BytesArray) + + // zstd compress zenc, err := zstd.NewWriter(buf) if err != nil { log.Panic(err) } - - enc := gob.NewEncoder(zenc) - cliBuffer := <-cli.FrameChan - enc.Encode(cliBuffer.BytesArray) - - err = zenc.Flush() + err = zenc.Close() if err != nil { log.Println(err) } @@ -244,17 +245,15 @@ func (nc *NetCard) runWrite() { if err != nil { log.Panic(err) } + zdec.Close() - dec := gob.NewDecoder(zdec) - + dec := gob.NewDecoder(buf) var bufs [][]byte err = dec.Decode(&bufs) if err != nil { log.Panic(err) } - zdec.Close() - for _, buf := range bufs { _, err := ifce.Write(buf) if err != nil {