mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
rename NewWriter to SelectWriter
This commit is contained in:
parent
7e6eaa7627
commit
70af1fee57
@ -14,8 +14,8 @@ var bufferPool = sync.Pool{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWriter 从池中取出一个 Writer
|
// SelectWriter 从池中取出一个 Writer
|
||||||
func NewWriter() *Writer {
|
func SelectWriter() *Writer {
|
||||||
w := bufferPool.Get().(*Writer)
|
w := bufferPool.Get().(*Writer)
|
||||||
if w == nil {
|
if w == nil {
|
||||||
return new(Writer)
|
return new(Writer)
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
type Writer bytes.Buffer
|
type Writer bytes.Buffer
|
||||||
|
|
||||||
func NewWriterF(f func(writer *Writer)) []byte {
|
func NewWriterF(f func(writer *Writer)) []byte {
|
||||||
w := NewWriter()
|
w := SelectWriter()
|
||||||
f(w)
|
f(w)
|
||||||
b := append([]byte(nil), w.Bytes()...)
|
b := append([]byte(nil), w.Bytes()...)
|
||||||
PutWriter(w)
|
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) {
|
func (w *Writer) WriteUniPacket(commandName string, sessionId, extraData, body []byte) {
|
||||||
w1 := NewWriter()
|
w1 := SelectWriter()
|
||||||
{ // WriteIntLvPacket
|
{ // WriteIntLvPacket
|
||||||
w1.WriteString(commandName)
|
w1.WriteString(commandName)
|
||||||
w1.WriteUInt32(8)
|
w1.WriteUInt32(8)
|
||||||
|
@ -49,7 +49,7 @@ func (c *QQClient) highwayUploadStream(ip uint32, port int, updKey []byte, strea
|
|||||||
chunk := *buf
|
chunk := *buf
|
||||||
defer binary.Put256KBytes(buf)
|
defer binary.Put256KBytes(buf)
|
||||||
|
|
||||||
w := binary.NewWriter()
|
w := binary.SelectWriter()
|
||||||
defer binary.PutWriter(w)
|
defer binary.PutWriter(w)
|
||||||
for {
|
for {
|
||||||
chunk = chunk[:chunkSize]
|
chunk = chunk[:chunkSize]
|
||||||
@ -134,7 +134,7 @@ func (c *QQClient) highwayUploadByBDH(stream io.Reader, length int64, cmdId int3
|
|||||||
chunk := *buf
|
chunk := *buf
|
||||||
defer binary.Put256KBytes(buf)
|
defer binary.Put256KBytes(buf)
|
||||||
|
|
||||||
w := binary.NewWriter()
|
w := binary.SelectWriter()
|
||||||
defer binary.PutWriter(w)
|
defer binary.PutWriter(w)
|
||||||
for {
|
for {
|
||||||
chunk = chunk[:chunkSize]
|
chunk = chunk[:chunkSize]
|
||||||
@ -270,7 +270,7 @@ func (c *QQClient) highwayUploadFileMultiThreadingByBDH(path string, cmdId int32
|
|||||||
return errors.Wrap(err, "echo error")
|
return errors.Wrap(err, "echo error")
|
||||||
}
|
}
|
||||||
buffer := make([]byte, blockSize)
|
buffer := make([]byte, blockSize)
|
||||||
w := binary.NewWriter()
|
w := binary.SelectWriter()
|
||||||
w.Reset()
|
w.Reset()
|
||||||
w.Grow(600 * 1024) // 复用,600k 不要放回池中
|
w.Grow(600 * 1024) // 复用,600k 不要放回池中
|
||||||
for {
|
for {
|
||||||
@ -368,7 +368,7 @@ func (c *QQClient) highwaySendHeartbreak(conn net.Conn) error {
|
|||||||
LocaleId: 2052,
|
LocaleId: 2052,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
w := binary.NewWriter()
|
w := binary.SelectWriter()
|
||||||
w.WriteByte(40)
|
w.WriteByte(40)
|
||||||
w.WriteUInt32(uint32(len(head)))
|
w.WriteUInt32(uint32(len(head)))
|
||||||
w.WriteUInt32(0)
|
w.WriteUInt32(0)
|
||||||
@ -406,7 +406,7 @@ func (c *QQClient) excitingUploadStream(stream io.ReadSeeker, cmdId int32, ticke
|
|||||||
chunkSize = 524288
|
chunkSize = 524288
|
||||||
)
|
)
|
||||||
chunk := make([]byte, chunkSize)
|
chunk := make([]byte, chunkSize)
|
||||||
w := binary.NewWriter()
|
w := binary.SelectWriter()
|
||||||
w.Reset()
|
w.Reset()
|
||||||
w.Grow(600 * 1024) // 复用,600k 不要放回池中
|
w.Grow(600 * 1024) // 复用,600k 不要放回池中
|
||||||
for {
|
for {
|
||||||
|
@ -132,7 +132,7 @@ func (c *QQClient) GetTts(text string) ([]byte, error) {
|
|||||||
return nil, errors.Wrap(err, "failed to post to tts server")
|
return nil, errors.Wrap(err, "failed to post to tts server")
|
||||||
}
|
}
|
||||||
ttsReader := binary.NewReader(rsp)
|
ttsReader := binary.NewReader(rsp)
|
||||||
ttsWriter := binary.NewWriter()
|
ttsWriter := binary.SelectWriter()
|
||||||
for {
|
for {
|
||||||
// 数据格式 69e(字符串) 十六进制 数据长度 0 为结尾
|
// 数据格式 69e(字符串) 十六进制 数据长度 0 为结尾
|
||||||
// 0D 0A (分隔符) payload 0D 0A
|
// 0D 0A (分隔符) payload 0D 0A
|
||||||
|
@ -50,7 +50,7 @@ func (e *EncryptECDH) generateKey(sPubKey string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EncryptECDH) DoEncrypt(d, k []byte) []byte {
|
func (e *EncryptECDH) DoEncrypt(d, k []byte) []byte {
|
||||||
w := binary.NewWriter()
|
w := binary.SelectWriter()
|
||||||
w.WriteByte(0x02)
|
w.WriteByte(0x02)
|
||||||
w.WriteByte(0x01)
|
w.WriteByte(0x01)
|
||||||
w.Write(k)
|
w.Write(k)
|
||||||
|
@ -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 {
|
func BuildUniPacket(uin int64, seq uint16, commandName string, encryptType byte, sessionID, extraData, key, body []byte) []byte {
|
||||||
return binary.NewWriterF(func(w *binary.Writer) {
|
return binary.NewWriterF(func(w *binary.Writer) {
|
||||||
w2 := binary.NewWriter()
|
w2 := binary.SelectWriter()
|
||||||
{ // w.WriteIntLvPacket
|
{ // w.WriteIntLvPacket
|
||||||
w2.WriteUInt32(0x0B)
|
w2.WriteUInt32(0x0B)
|
||||||
w2.WriteByte(encryptType)
|
w2.WriteByte(encryptType)
|
||||||
@ -36,7 +36,7 @@ func BuildUniPacket(uin int64, seq uint16, commandName string, encryptType byte,
|
|||||||
w2.WriteString(strconv.FormatInt(uin, 10))
|
w2.WriteString(strconv.FormatInt(uin, 10))
|
||||||
|
|
||||||
// inline NewWriterF
|
// inline NewWriterF
|
||||||
w3 := binary.NewWriter()
|
w3 := binary.SelectWriter()
|
||||||
w3.WriteUniPacket(commandName, sessionID, extraData, body)
|
w3.WriteUniPacket(commandName, sessionID, extraData, body)
|
||||||
w2.EncryptAndWrite(key, w3.Bytes())
|
w2.EncryptAndWrite(key, w3.Bytes())
|
||||||
binary.PutWriter(w3)
|
binary.PutWriter(w3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user