mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-24 04:27:08 +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
|
return nil
|
||||||
}
|
}
|
||||||
data = w.TransBytes()
|
data = w.TransUnderlyingBytes()
|
||||||
if len(data) < bound {
|
if len(data) < bound {
|
||||||
bound = len(data)
|
bound = len(data)
|
||||||
endl = "."
|
endl = "."
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func (p *packet) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.dat = w.TransBytes()
|
p.dat = w.TransUnderlyingBytes()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package helper
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/fumiama/orbyte"
|
"github.com/fumiama/orbyte"
|
||||||
"github.com/fumiama/orbyte/pbuf"
|
"github.com/fumiama/orbyte/pbuf"
|
||||||
@@ -17,20 +16,23 @@ type Writer orbyte.Item[bytes.Buffer]
|
|||||||
func NewWriterF(f func(writer *Writer)) pbuf.Bytes {
|
func NewWriterF(f func(writer *Writer)) pbuf.Bytes {
|
||||||
w := SelectWriter()
|
w := SelectWriter()
|
||||||
f(w)
|
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) {
|
func (w *Writer) Write(b []byte) (n int, err error) {
|
||||||
return (*orbyte.Item[bytes.Buffer])(w).Pointer().Write(b)
|
return w.pp().Write(b)
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) WriteHex(h string) {
|
|
||||||
b, _ := hex.DecodeString(h)
|
|
||||||
w.Write(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) WriteByte(b byte) error {
|
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) {
|
func (w *Writer) WriteUInt16(v uint16) {
|
||||||
@@ -53,25 +55,29 @@ func (w *Writer) WriteUInt64(v uint64) {
|
|||||||
|
|
||||||
func (w *Writer) WriteString(v string) {
|
func (w *Writer) WriteString(v string) {
|
||||||
//w.WriteUInt32(uint32(len(v) + 4))
|
//w.WriteUInt32(uint32(len(v) + 4))
|
||||||
(*orbyte.Item[bytes.Buffer])(w).Pointer().WriteString(v)
|
w.pp().WriteString(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) Len() int {
|
func (w *Writer) Len() int {
|
||||||
return (*orbyte.Item[bytes.Buffer])(w).Pointer().Len()
|
return w.pp().Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) UnsafeBytes() []byte {
|
func (w *Writer) UnsafeBytes() []byte {
|
||||||
return (*orbyte.Item[bytes.Buffer])(w).Pointer().Bytes()
|
return w.pp().Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) TransBytes() []byte {
|
func (w *Writer) TransUnderlyingBytes() []byte {
|
||||||
return (*orbyte.Item[bytes.Buffer])(w).Trans().Pointer().Bytes()
|
return w.p().Trans().Pointer().Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) TransBytes() pbuf.Bytes {
|
||||||
|
return pbuf.BufferItemToBytes(w.p().Trans())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) Reset() {
|
func (w *Writer) Reset() {
|
||||||
(*orbyte.Item[bytes.Buffer])(w).Pointer().Reset()
|
w.pp().Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) Grow(n int) {
|
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