1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-07-01 08:10:22 +08:00

optimize(all): drop lstnq & impl. orbyte

This commit is contained in:
源文雨
2025-02-25 19:38:16 +09:00
parent 4b60801a0f
commit 9f36504635
22 changed files with 501 additions and 573 deletions

View File

@@ -1,14 +1,18 @@
package tcp
import (
"bytes"
"encoding/binary"
"errors"
"io"
"net"
"runtime"
"time"
"github.com/fumiama/WireGold/config"
"github.com/fumiama/WireGold/helper"
"github.com/fumiama/orbyte"
"github.com/fumiama/orbyte/pbuf"
"github.com/sirupsen/logrus"
)
@@ -33,17 +37,19 @@ var (
type packet struct {
typ packetType
len uint16
dat []byte
dat pbuf.Bytes
io.ReaderFrom
io.WriterTo
}
func (p *packet) pack() (net.Buffers, func()) {
d, cl := helper.OpenWriterF(func(w *helper.Writer) {
d := helper.NewWriterF(func(w *helper.Writer) {
w.WriteByte(byte(p.typ))
w.WriteUInt16(p.len)
})
return net.Buffers{magicbuf, d, p.dat}, cl
return net.Buffers{magicbuf, d.Bytes(), p.dat.Bytes()}, func() {
runtime.KeepAlive(d)
}
}
func (p *packet) Read(_ []byte) (int, error) {
@@ -81,7 +87,7 @@ func (p *packet) ReadFrom(r io.Reader) (n int64, err error) {
if err != nil {
return
}
p.dat = w.Bytes()
p.dat = pbuf.BufferItemToBytes((*orbyte.Item[bytes.Buffer])(w).Trans())
return
}