lib9p

Go 9P library.
Log | Files | Refs

commit ba9df889ba19e9329d7ca218a8fc76fc619143bb
parent a97ff77ac15a8bacedb7e251f11933f31bf4fc20
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed,  6 Sep 2023 10:15:41 +0900

add rest of the messages

Diffstat:
Mfcall.go | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Mparse.go | 20++++++++++++++++++++
2 files changed, 128 insertions(+), 5 deletions(-)

diff --git a/fcall.go b/fcall.go @@ -33,8 +33,8 @@ const ( Rremove = 123 Tstat = 124 Rstat = 125 - TwStat = 126 - RwStat = 127 + Twstat = 126 + Rwstat = 127 Tmax = 128 ) @@ -1121,10 +1121,54 @@ func (msg *RClunk) String() string { } type TRemove struct{ + tag uint16 + fid uint32 +} +func newTRemove(buf []byte) *TRemove { + msg := new(TRemove) + msg.tag = gbit16(buf[5:7]) + msg.fid = gbit32(buf[7:11]) + return msg +} +func (msg *TRemove) Size() uint32 { return 4 + 1 + 2 + 4 } +func (msg *TRemove) Type() MsgType { return Tremove } +func (msg *TRemove) Tag() uint16 { return msg.tag } +func (msg *TRemove) Fid() uint32 { return msg.fid } +func (msg *TRemove) marshal() []byte { + m := make([]byte, msg.Size()) + pbit32(m[0:4], msg.Size()) + m[4] = uint8(msg.Type()) + pbit16(m[5:7], msg.Tag()) + pbit32(m[7:11], msg.Fid()) + return m +} +func (msg *TRemove) String() string { + return fmt.Sprintf("Tremove tag %d fid %d", msg.Tag(), msg.Fid()) +} + +type RRemove struct{ + tag uint16 } -type RRemove struct{} +func newRRemove(buf []byte) *RRemove { + msg := new(RRemove) + msg.tag = gbit16(buf[5:7]) + return msg +} +func (msg *RRemove) Size() uint32 { return 4 + 1 + 2 } +func (msg *RRemove) Type() MsgType { return Rremove } +func (msg *RRemove) Tag() uint16 { return msg.tag } +func (msg *RRemove) marshal() []byte { + m := make([]byte, msg.Size()) + pbit32(m[0:4], msg.Size()) + m[4] = uint8(msg.Type()) + pbit16(m[5:7], msg.Tag()) + return m +} +func (msg *RRemove) String() string { + return fmt.Sprintf("Rremove tag %d", msg.Tag()) +} type TStat struct { size uint32 @@ -1190,5 +1234,64 @@ func (msg *RStat) String() string { return fmt.Sprintf("Rstat tag %d Stat %s", msg.Tag(), msg.stat) } -type TWStat struct{} -type RWStat struct{} +type TWStat struct{ + tag uint16 + fid uint32 + stat *Stat +} + +func newTWStat(buf []byte) *TWStat { + msg := new(TWStat) + msg.tag = gbit16(buf[5:7]) + msg.fid = gbit32(buf[7:11]) + msg.stat = newStat(buf[13:]) + return msg +} +func (msg *TWStat) Size() uint32 { + return uint32(4 + 1 + 2 + 4 + 2 + 2 + msg.stat.size()) +} +func (msg *TWStat) Type() MsgType { return Twstat } +func (msg *TWStat) Tag() uint16 { return msg.tag } +func (msg *TWStat) Fid() uint32 { return msg.fid } +func (msg *TWStat) marshal() []byte { + buf := make([]byte, msg.Size()) + pbit32(buf[0:4], msg.Size()) + buf[4] = uint8(msg.Type()) + pbit16(buf[5:7], msg.Tag()) + pbit32(buf[7:11], msg.Fid()) + + fiBuf := msg.stat.marshal() + pbit16(buf[11:13], uint16(len(fiBuf))) + for i := 0; i < len(fiBuf); i++ { + buf[13+i] = fiBuf[i] + } + return buf +} + +func (msg *TWStat) String() string { + return fmt.Sprintf("Twstat tag %d fid %d Stat %s", msg.Tag(), msg.Fid(), msg.stat) +} + + +type RWStat struct{ + tag uint16 +} + +func newRWStat(buf []byte) *RWStat { + msg := new(RWStat) + msg.tag = gbit16(buf[5:7]) + return msg +} +func (msg *RWStat) Size() uint32 { return 4 + 1 + 2 } +func (msg *RWStat) Type() MsgType { return Rwstat } +func (msg *RWStat) Tag() uint16 { return msg.tag } +func (msg *RWStat) marshal() []byte { + m := make([]byte, msg.Size()) + pbit32(m[0:4], msg.Size()) + m[4] = uint8(msg.Type()) + pbit16(m[5:7], msg.Tag()) + return m +} +func (msg *RWStat) String() string { + return fmt.Sprintf("Rwstat tag %d", msg.Tag()) +} diff --git a/parse.go b/parse.go @@ -49,6 +49,10 @@ func unmarshal(buf []byte) (Msg, error) { return newRAttach(buf), nil case Rerror: return newRError(buf), nil + case Tflush: + return newTFlush(buf), nil + case Rflush: + return newRFlush(buf), nil case Twalk: return newTWalk(buf), nil case Rwalk: @@ -57,18 +61,34 @@ func unmarshal(buf []byte) (Msg, error) { return newTOpen(buf), nil case Ropen: return newROpen(buf), nil + case Tcreate: + return newTCreat(buf), nil + case Rcreate: + return newRCreate(buf), nil case Tread: return newTRead(buf), nil case Rread: return newRRead(buf), nil + case Twrite: + return newTWrite(buf), nil + case Rwrite: + return newRWrite(buf), nil case Tclunk: return newTClunk(buf), nil case Rclunk: return newRClunk(buf), nil + case Tremove: + return newTRemove(buf), nil + case Rremove: + return newRRemove(buf), nil case Tstat: return newTStat(buf), nil case Rstat: return newRStat(buf), nil + case Twstat: + return newTWStat(buf), nil + case Rwstat: + return newRWStat(buf), nil default: return nil, fmt.Errorf("unknown message type %v", t) }