From 70af1fee5728f820e15580146e24c2b9adcb840f Mon Sep 17 00:00:00 2001 From: Blackjack200 Date: Sun, 21 Nov 2021 12:58:34 +0800 Subject: [PATCH] rename NewWriter to SelectWriter --- binary/pool.go | 4 ++-- binary/writer.go | 4 ++-- client/highway.go | 10 +++++----- client/http_api.go | 2 +- internal/crypto/crypto.go | 2 +- internal/packets/builders.go | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/binary/pool.go b/binary/pool.go index 5379f239..9f6e3f05 100644 --- a/binary/pool.go +++ b/binary/pool.go @@ -14,8 +14,8 @@ var bufferPool = sync.Pool{ }, } -// NewWriter 从池中取出一个 Writer -func NewWriter() *Writer { +// SelectWriter 从池中取出一个 Writer +func SelectWriter() *Writer { w := bufferPool.Get().(*Writer) if w == nil { return new(Writer) diff --git a/binary/writer.go b/binary/writer.go index aef161a2..37e99d2d 100644 --- a/binary/writer.go +++ b/binary/writer.go @@ -12,7 +12,7 @@ import ( type Writer bytes.Buffer func NewWriterF(f func(writer *Writer)) []byte { - w := NewWriter() + w := SelectWriter() f(w) b := append([]byte(nil), w.Bytes()...) PutWriter(w) @@ -81,7 +81,7 @@ func (w *Writer) WriteIntLvPacket(offset int, f func(writer *Writer)) { } func (w *Writer) WriteUniPacket(commandName string, sessionId, extraData, body []byte) { - w1 := NewWriter() + w1 := SelectWriter() { // WriteIntLvPacket w1.WriteString(commandName) w1.WriteUInt32(8) diff --git a/client/highway.go b/client/highway.go index e409e065..0dcb00a0 100644 --- a/client/highway.go +++ b/client/highway.go @@ -49,7 +49,7 @@ func (c *QQClient) highwayUploadStream(ip uint32, port int, updKey []byte, strea chunk := *buf defer binary.Put256KBytes(buf) - w := binary.NewWriter() + w := binary.SelectWriter() defer binary.PutWriter(w) for { chunk = chunk[:chunkSize] @@ -134,7 +134,7 @@ func (c *QQClient) highwayUploadByBDH(stream io.Reader, length int64, cmdId int3 chunk := *buf defer binary.Put256KBytes(buf) - w := binary.NewWriter() + w := binary.SelectWriter() defer binary.PutWriter(w) for { chunk = chunk[:chunkSize] @@ -270,7 +270,7 @@ func (c *QQClient) highwayUploadFileMultiThreadingByBDH(path string, cmdId int32 return errors.Wrap(err, "echo error") } buffer := make([]byte, blockSize) - w := binary.NewWriter() + w := binary.SelectWriter() w.Reset() w.Grow(600 * 1024) // 复用,600k 不要放回池中 for { @@ -368,7 +368,7 @@ func (c *QQClient) highwaySendHeartbreak(conn net.Conn) error { LocaleId: 2052, }, }) - w := binary.NewWriter() + w := binary.SelectWriter() w.WriteByte(40) w.WriteUInt32(uint32(len(head))) w.WriteUInt32(0) @@ -406,7 +406,7 @@ func (c *QQClient) excitingUploadStream(stream io.ReadSeeker, cmdId int32, ticke chunkSize = 524288 ) chunk := make([]byte, chunkSize) - w := binary.NewWriter() + w := binary.SelectWriter() w.Reset() w.Grow(600 * 1024) // 复用,600k 不要放回池中 for { diff --git a/client/http_api.go b/client/http_api.go index 69a71698..3f14df0f 100644 --- a/client/http_api.go +++ b/client/http_api.go @@ -132,7 +132,7 @@ func (c *QQClient) GetTts(text string) ([]byte, error) { return nil, errors.Wrap(err, "failed to post to tts server") } ttsReader := binary.NewReader(rsp) - ttsWriter := binary.NewWriter() + ttsWriter := binary.SelectWriter() for { // 数据格式 69e(字符串) 十六进制 数据长度 0 为结尾 // 0D 0A (分隔符) payload 0D 0A diff --git a/internal/crypto/crypto.go b/internal/crypto/crypto.go index 7de14c09..a3b006a7 100644 --- a/internal/crypto/crypto.go +++ b/internal/crypto/crypto.go @@ -50,7 +50,7 @@ func (e *EncryptECDH) generateKey(sPubKey string) { } func (e *EncryptECDH) DoEncrypt(d, k []byte) []byte { - w := binary.NewWriter() + w := binary.SelectWriter() w.WriteByte(0x02) w.WriteByte(0x01) w.Write(k) diff --git a/internal/packets/builders.go b/internal/packets/builders.go index a234ed5f..e3e1685e 100644 --- a/internal/packets/builders.go +++ b/internal/packets/builders.go @@ -27,7 +27,7 @@ func BuildLoginPacket(uin int64, bodyType byte, key, body, extraData []byte) []b func BuildUniPacket(uin int64, seq uint16, commandName string, encryptType byte, sessionID, extraData, key, body []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { - w2 := binary.NewWriter() + w2 := binary.SelectWriter() { // w.WriteIntLvPacket w2.WriteUInt32(0x0B) w2.WriteByte(encryptType) @@ -36,7 +36,7 @@ func BuildUniPacket(uin int64, seq uint16, commandName string, encryptType byte, w2.WriteString(strconv.FormatInt(uin, 10)) // inline NewWriterF - w3 := binary.NewWriter() + w3 := binary.SelectWriter() w3.WriteUniPacket(commandName, sessionID, extraData, body) w2.EncryptAndWrite(key, w3.Bytes()) binary.PutWriter(w3)