Blame


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