Blob


1 package p9p
3 import "fmt"
5 // Message represents the target of an fcall.
6 type Message interface {
7 // Type returns the type of call for the target message.
8 Type() FcallType
9 }
11 // newMessage returns a new instance of the message based on the Fcall type.
12 func newMessage(typ FcallType) (Message, error) {
13 switch typ {
14 case Tversion:
15 return MessageTversion{}, nil
16 case Rversion:
17 return MessageRversion{}, nil
18 case Tauth:
19 return MessageTauth{}, nil
20 case Rauth:
21 return MessageRauth{}, nil
22 case Tattach:
23 return MessageTattach{}, nil
24 case Rattach:
25 return MessageRattach{}, nil
26 case Rerror:
27 return MessageRerror{}, nil
28 case Tflush:
29 return MessageTflush{}, nil
30 case Rflush:
31 return MessageRflush{}, nil // No message body for this response.
32 case Twalk:
33 return MessageTwalk{}, nil
34 case Rwalk:
35 return MessageRwalk{}, nil
36 case Topen:
37 return MessageTopen{}, nil
38 case Ropen:
39 return MessageRopen{}, nil
40 case Tcreate:
41 return MessageTcreate{}, nil
42 case Rcreate:
43 return MessageRcreate{}, nil
44 case Tread:
45 return MessageTread{}, nil
46 case Rread:
47 return MessageRread{}, nil
48 case Twrite:
49 return MessageTwrite{}, nil
50 case Rwrite:
51 return MessageRwrite{}, nil
52 case Tclunk:
53 return MessageTclunk{}, nil
54 case Rclunk:
55 return MessageRclunk{}, nil // no response body
56 case Tremove:
57 return MessageTremove{}, nil
58 case Rremove:
59 return MessageRremove{}, nil
60 case Tstat:
61 return MessageTstat{}, nil
62 case Rstat:
63 return MessageRstat{}, nil
64 case Twstat:
65 return MessageTwstat{}, nil
66 case Rwstat:
67 return MessageRwstat{}, nil
68 }
70 return nil, fmt.Errorf("unknown message type")
71 }
73 // MessageVersion encodes the message body for Tversion and Rversion RPC
74 // calls. The body is identical in both directions.
75 type MessageTversion struct {
76 MSize uint32
77 Version string
78 }
80 type MessageRversion struct {
81 MSize uint32
82 Version string
83 }
85 type MessageTauth struct {
86 Afid Fid
87 Uname string
88 Aname string
89 }
91 type MessageRauth struct {
92 Qid Qid
93 }
95 type MessageTflush struct {
96 Oldtag Tag
97 }
99 type MessageRflush struct{}
101 type MessageTattach struct {
102 Fid Fid
103 Afid Fid
104 Uname string
105 Aname string
108 type MessageRattach struct {
109 Qid Qid
112 type MessageTwalk struct {
113 Fid Fid
114 Newfid Fid
115 Wnames []string
118 type MessageRwalk struct {
119 Qids []Qid
122 type MessageTopen struct {
123 Fid Fid
124 Mode Flag
127 type MessageRopen struct {
128 Qid Qid
129 IOUnit uint32
132 type MessageTcreate struct {
133 Fid Fid
134 Name string
135 Perm uint32
136 Mode Flag
139 type MessageRcreate struct {
140 Qid Qid
141 IOUnit uint32
144 type MessageTread struct {
145 Fid Fid
146 Offset uint64
147 Count uint32
150 type MessageRread struct {
151 Data []byte
154 type MessageTwrite struct {
155 Fid Fid
156 Offset uint64
157 Data []byte
160 type MessageRwrite struct {
161 Count uint32
164 type MessageTclunk struct {
165 Fid Fid
168 type MessageRclunk struct{}
170 type MessageTremove struct {
171 Fid Fid
174 type MessageRremove struct{}
176 type MessageTstat struct {
177 Fid Fid
180 type MessageRstat struct {
181 Stat Dir
184 type MessageTwstat struct {
185 Fid Fid
186 Stat Dir
189 type MessageRwstat struct{}
191 func (MessageTversion) Type() FcallType { return Tversion }
192 func (MessageRversion) Type() FcallType { return Rversion }
193 func (MessageTauth) Type() FcallType { return Tauth }
194 func (MessageRauth) Type() FcallType { return Rauth }
195 func (MessageTflush) Type() FcallType { return Tflush }
196 func (MessageRflush) Type() FcallType { return Rflush }
197 func (MessageTattach) Type() FcallType { return Tattach }
198 func (MessageRattach) Type() FcallType { return Rattach }
199 func (MessageTwalk) Type() FcallType { return Twalk }
200 func (MessageRwalk) Type() FcallType { return Rwalk }
201 func (MessageTopen) Type() FcallType { return Topen }
202 func (MessageRopen) Type() FcallType { return Ropen }
203 func (MessageTcreate) Type() FcallType { return Tcreate }
204 func (MessageRcreate) Type() FcallType { return Rcreate }
205 func (MessageTread) Type() FcallType { return Tread }
206 func (MessageRread) Type() FcallType { return Rread }
207 func (MessageTwrite) Type() FcallType { return Twrite }
208 func (MessageRwrite) Type() FcallType { return Rwrite }
209 func (MessageTclunk) Type() FcallType { return Tclunk }
210 func (MessageRclunk) Type() FcallType { return Rclunk }
211 func (MessageTremove) Type() FcallType { return Tremove }
212 func (MessageRremove) Type() FcallType { return Rremove }
213 func (MessageTstat) Type() FcallType { return Tstat }
214 func (MessageRstat) Type() FcallType { return Rstat }
215 func (MessageTwstat) Type() FcallType { return Twstat }
216 func (MessageRwstat) Type() FcallType { return Rwstat }