Blame


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