mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-04 23:40:26 +08:00
optimize(helper): writer decl.
This commit is contained in:
@@ -46,7 +46,7 @@ func (m *Me) wait(data []byte) *orbyte.Item[head.Packet] {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
data = w.TransBytes()
|
||||
data = w.TransUnderlyingBytes()
|
||||
if len(data) < bound {
|
||||
bound = len(data)
|
||||
endl = "."
|
||||
|
||||
@@ -80,7 +80,7 @@ func (p *packet) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
p.dat = w.TransBytes()
|
||||
p.dat = w.TransUnderlyingBytes()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ package helper
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/fumiama/orbyte"
|
||||
"github.com/fumiama/orbyte/pbuf"
|
||||
@@ -17,20 +16,23 @@ type Writer orbyte.Item[bytes.Buffer]
|
||||
func NewWriterF(f func(writer *Writer)) pbuf.Bytes {
|
||||
w := SelectWriter()
|
||||
f(w)
|
||||
return pbuf.BufferItemToBytes((*orbyte.Item[bytes.Buffer])(w).Trans())
|
||||
return w.TransBytes()
|
||||
}
|
||||
|
||||
func (w *Writer) p() *orbyte.Item[bytes.Buffer] {
|
||||
return (*orbyte.Item[bytes.Buffer])(w)
|
||||
}
|
||||
|
||||
func (w *Writer) pp() *bytes.Buffer {
|
||||
return w.p().Pointer()
|
||||
}
|
||||
|
||||
func (w *Writer) Write(b []byte) (n int, err error) {
|
||||
return (*orbyte.Item[bytes.Buffer])(w).Pointer().Write(b)
|
||||
}
|
||||
|
||||
func (w *Writer) WriteHex(h string) {
|
||||
b, _ := hex.DecodeString(h)
|
||||
w.Write(b)
|
||||
return w.pp().Write(b)
|
||||
}
|
||||
|
||||
func (w *Writer) WriteByte(b byte) error {
|
||||
return (*orbyte.Item[bytes.Buffer])(w).Pointer().WriteByte(b)
|
||||
return w.pp().WriteByte(b)
|
||||
}
|
||||
|
||||
func (w *Writer) WriteUInt16(v uint16) {
|
||||
@@ -53,25 +55,29 @@ func (w *Writer) WriteUInt64(v uint64) {
|
||||
|
||||
func (w *Writer) WriteString(v string) {
|
||||
//w.WriteUInt32(uint32(len(v) + 4))
|
||||
(*orbyte.Item[bytes.Buffer])(w).Pointer().WriteString(v)
|
||||
w.pp().WriteString(v)
|
||||
}
|
||||
|
||||
func (w *Writer) Len() int {
|
||||
return (*orbyte.Item[bytes.Buffer])(w).Pointer().Len()
|
||||
return w.pp().Len()
|
||||
}
|
||||
|
||||
func (w *Writer) UnsafeBytes() []byte {
|
||||
return (*orbyte.Item[bytes.Buffer])(w).Pointer().Bytes()
|
||||
return w.pp().Bytes()
|
||||
}
|
||||
|
||||
func (w *Writer) TransBytes() []byte {
|
||||
return (*orbyte.Item[bytes.Buffer])(w).Trans().Pointer().Bytes()
|
||||
func (w *Writer) TransUnderlyingBytes() []byte {
|
||||
return w.p().Trans().Pointer().Bytes()
|
||||
}
|
||||
|
||||
func (w *Writer) TransBytes() pbuf.Bytes {
|
||||
return pbuf.BufferItemToBytes(w.p().Trans())
|
||||
}
|
||||
|
||||
func (w *Writer) Reset() {
|
||||
(*orbyte.Item[bytes.Buffer])(w).Pointer().Reset()
|
||||
w.pp().Reset()
|
||||
}
|
||||
|
||||
func (w *Writer) Grow(n int) {
|
||||
(*orbyte.Item[bytes.Buffer])(w).Pointer().Grow(n)
|
||||
w.pp().Grow(n)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user