Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 0 additions & 176 deletions bannet/client.go

This file was deleted.

5 changes: 2 additions & 3 deletions bannet/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ func (c *Connection) StartReader() {
}

// 头部之后, 先按 IDLen 读取 msgID 字符串
mImpl := msg.(*Message)
if mImpl.IDLen > 0 {
idBuf := make([]byte, mImpl.IDLen)
if msg.IDLen > 0 {
idBuf := make([]byte, msg.IDLen)
if _, err := io.ReadFull(reader, idBuf); err != nil {
slog.Error("conn read msgID failed", "connID", c.ConnID, "error", err)
return
Expand Down
4 changes: 2 additions & 2 deletions bannet/datapack.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (dp *DataPack) HeadLen() uint32 {

// Pack 编码一帧。按最终长度一次性分配并直接写入定长头部,不经 bytes.Buffer 的增量扩容,
// 也不经 binary.Write 的反射路径——Pack 位于每个响应的必经路径上。
func (dp *DataPack) Pack(msg Frame) ([]byte, error) {
func (dp *DataPack) Pack(msg *Message) ([]byte, error) {
id := msg.MsgID()
if len(id) > 0xFFFF {
return nil, fmt.Errorf("msgID too long: %d", len(id))
Expand All @@ -43,7 +43,7 @@ func (dp *DataPack) Pack(msg Frame) ([]byte, error) {

// UnPack 只解析定长头部 (6 字节), 返回带 DataLen 与 IDLen 的占位 Message;
// 调用方拿到 IDLen 后, 还需要从连接读取 IDLen+DataLen 字节填充 Id 与 Data。
func (dp *DataPack) UnPack(data []byte) (Frame, error) {
func (dp *DataPack) UnPack(data []byte) (*Message, error) {
if len(data) < int(dp.HeadLen()) {
return nil, errors.New("head too short")
}
Expand Down
13 changes: 2 additions & 11 deletions bannet/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type ConnRegistry interface {

type Codec interface {
HeadLen() uint32
Pack(msg Frame) ([]byte, error)
UnPack([]byte) (Frame, error)
Pack(msg *Message) ([]byte, error)
UnPack([]byte) (*Message, error)
}

type Dispatcher interface {
Expand Down Expand Up @@ -63,12 +63,3 @@ type Conn interface {
Property(key string) any
RemoveProperty(key string)
}

type Frame interface {
MsgID() string
Payload() []byte
MsgLen() uint32
SetMsgLen(uint32)
SetData([]byte)
SetMsgID(string)
}
2 changes: 0 additions & 2 deletions bannet/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ type Message struct {
Data []byte
}

var _ Frame = &Message{}

func NewMessage(id string, data []byte) *Message {
return &Message{
ID: id,
Expand Down
4 changes: 2 additions & 2 deletions bannet/request.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package bannet

type request struct {
msg Frame
msg *Message
conn Conn
}

var _ Request = &request{}

func newRequest(msg Frame, conn Conn) *request {
func newRequest(msg *Message, conn Conn) *request {
return &request{
msg: msg,
conn: conn,
Expand Down
2 changes: 1 addition & 1 deletion bannet/wire_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestScanResponseSurvivesWire(t *testing.T) {
if err != nil {
t.Fatalf("UnPack 拒绝了大响应(MaxPackageSize 太小?): %v", err)
}
m := tempMsg.(*bannet.Message)
m := tempMsg

off := headLen + int(m.IDLen)
data := packet[off : off+int(tempMsg.MsgLen())]
Expand Down
Loading
Loading