From 3125dbb804e8c3e0c1eb86e9240be04503858622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Tue, 30 Aug 2022 11:44:08 +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 --- netcard.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/netcard.go b/netcard.go index a69c0b9..1387dc2 100644 --- a/netcard.go +++ b/netcard.go @@ -16,6 +16,7 @@ import ( "sync/atomic" "time" + "github.com/klauspost/compress/zstd" "github.com/songgao/packets/ethernet" "github.com/songgao/water" "github.com/songgao/water/waterutil" @@ -97,14 +98,14 @@ func (cli *RPCClient) run() { } // zstd compress - // zenc, err := zstd.NewWriter(buf) - // if err != nil { - // log.Panic(err) - // } - // err = zenc.Flush() - // if err != nil { - // log.Println(err) - // } + zenc, err := zstd.NewWriter(buf) + if err != nil { + log.Panic(err) + } + err = zenc.Flush() + if err != nil { + log.Println(err) + } // 发到对面的网卡 err = stream.Send(&gen.Request{ @@ -259,14 +260,14 @@ func (nc *NetCard) runWrite() { log.Printf("get wframes bytes len: %d", len(wframe)) var buf = bytes.NewBuffer(wframe) - // zdec, err := zstd.NewReader(buf) - // if err != nil { - // log.Panic(err) - // } + var zdec *zstd.Decoder + zdec, err = zstd.NewReader(buf) + if err != nil { + log.Panic(err) + } + zdec.Close() - // zdec.Close() - - dec := gob.NewDecoder(buf) + dec := gob.NewDecoder(zdec) var bufs [][]byte err = dec.Decode(&bufs) if err != nil {