1 269e4d4b 2015-11-05 stephen.d package p9pnew
3 269e4d4b 2015-11-05 stephen.d import "fmt"
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
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
70 269e4d4b 2015-11-05 stephen.d return nil, fmt.Errorf("unknown message type")
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
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
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
91 269e4d4b 2015-11-05 stephen.d type MessageRauth struct {
92 269e4d4b 2015-11-05 stephen.d Qid Qid
95 269e4d4b 2015-11-05 stephen.d type MessageTflush struct {
96 269e4d4b 2015-11-05 stephen.d Oldtag Tag
99 269e4d4b 2015-11-05 stephen.d type MessageRflush struct{}
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
108 269e4d4b 2015-11-05 stephen.d type MessageRattach struct {
109 269e4d4b 2015-11-05 stephen.d Qid Qid
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
118 269e4d4b 2015-11-05 stephen.d type MessageRwalk struct {
119 269e4d4b 2015-11-05 stephen.d Qids []Qid
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
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
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
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
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
150 269e4d4b 2015-11-05 stephen.d type MessageRread struct {
151 269e4d4b 2015-11-05 stephen.d Data []byte
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
160 269e4d4b 2015-11-05 stephen.d type MessageRwrite struct {
161 269e4d4b 2015-11-05 stephen.d Count uint32
164 269e4d4b 2015-11-05 stephen.d type MessageTclunk struct {
165 269e4d4b 2015-11-05 stephen.d Fid Fid
168 269e4d4b 2015-11-05 stephen.d type MessageRclunk struct{}
170 269e4d4b 2015-11-05 stephen.d type MessageTremove struct {
171 269e4d4b 2015-11-05 stephen.d Fid Fid
174 269e4d4b 2015-11-05 stephen.d type MessageRremove struct{}
176 269e4d4b 2015-11-05 stephen.d type MessageTstat struct {
177 269e4d4b 2015-11-05 stephen.d Fid Fid
180 269e4d4b 2015-11-05 stephen.d type MessageRstat struct {
181 269e4d4b 2015-11-05 stephen.d Stat Dir
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
189 269e4d4b 2015-11-05 stephen.d type MessageRwstat struct{}
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 }