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 a0568195 2016-05-23 stevvooe // FcallType encodes the message type for the target Fcall.
6 4b33cdd0 2015-11-30 stephen.d type FcallType uint8
7 4b33cdd0 2015-11-30 stephen.d
8 a0568195 2016-05-23 stevvooe // Definitions for Fcall's used in 9P2000.
9 4b33cdd0 2015-11-30 stephen.d const (
10 4b33cdd0 2015-11-30 stephen.d Tversion FcallType = iota + 100
11 4b33cdd0 2015-11-30 stephen.d Rversion
12 4b33cdd0 2015-11-30 stephen.d Tauth
13 4b33cdd0 2015-11-30 stephen.d Rauth
14 4b33cdd0 2015-11-30 stephen.d Tattach
15 4b33cdd0 2015-11-30 stephen.d Rattach
16 4b33cdd0 2015-11-30 stephen.d Terror
17 4b33cdd0 2015-11-30 stephen.d Rerror
18 4b33cdd0 2015-11-30 stephen.d Tflush
19 4b33cdd0 2015-11-30 stephen.d Rflush
20 4b33cdd0 2015-11-30 stephen.d Twalk
21 4b33cdd0 2015-11-30 stephen.d Rwalk
22 4b33cdd0 2015-11-30 stephen.d Topen
23 4b33cdd0 2015-11-30 stephen.d Ropen
24 4b33cdd0 2015-11-30 stephen.d Tcreate
25 4b33cdd0 2015-11-30 stephen.d Rcreate
26 4b33cdd0 2015-11-30 stephen.d Tread
27 4b33cdd0 2015-11-30 stephen.d Rread
28 4b33cdd0 2015-11-30 stephen.d Twrite
29 4b33cdd0 2015-11-30 stephen.d Rwrite
30 4b33cdd0 2015-11-30 stephen.d Tclunk
31 4b33cdd0 2015-11-30 stephen.d Rclunk
32 4b33cdd0 2015-11-30 stephen.d Tremove
33 4b33cdd0 2015-11-30 stephen.d Rremove
34 4b33cdd0 2015-11-30 stephen.d Tstat
35 4b33cdd0 2015-11-30 stephen.d Rstat
36 4b33cdd0 2015-11-30 stephen.d Twstat
37 4b33cdd0 2015-11-30 stephen.d Rwstat
38 4b33cdd0 2015-11-30 stephen.d Tmax
39 4b33cdd0 2015-11-30 stephen.d )
40 4b33cdd0 2015-11-30 stephen.d
41 4b33cdd0 2015-11-30 stephen.d func (fct FcallType) String() string {
42 4b33cdd0 2015-11-30 stephen.d switch fct {
43 4b33cdd0 2015-11-30 stephen.d case Tversion:
44 4b33cdd0 2015-11-30 stephen.d return "Tversion"
45 4b33cdd0 2015-11-30 stephen.d case Rversion:
46 4b33cdd0 2015-11-30 stephen.d return "Rversion"
47 4b33cdd0 2015-11-30 stephen.d case Tauth:
48 4b33cdd0 2015-11-30 stephen.d return "Tauth"
49 4b33cdd0 2015-11-30 stephen.d case Rauth:
50 4b33cdd0 2015-11-30 stephen.d return "Rauth"
51 4b33cdd0 2015-11-30 stephen.d case Tattach:
52 4b33cdd0 2015-11-30 stephen.d return "Tattach"
53 4b33cdd0 2015-11-30 stephen.d case Rattach:
54 4b33cdd0 2015-11-30 stephen.d return "Rattach"
55 4b33cdd0 2015-11-30 stephen.d case Terror:
56 4b33cdd0 2015-11-30 stephen.d // invalid.
57 4b33cdd0 2015-11-30 stephen.d return "Terror"
58 4b33cdd0 2015-11-30 stephen.d case Rerror:
59 4b33cdd0 2015-11-30 stephen.d return "Rerror"
60 4b33cdd0 2015-11-30 stephen.d case Tflush:
61 4b33cdd0 2015-11-30 stephen.d return "Tflush"
62 4b33cdd0 2015-11-30 stephen.d case Rflush:
63 4b33cdd0 2015-11-30 stephen.d return "Rflush"
64 4b33cdd0 2015-11-30 stephen.d case Twalk:
65 4b33cdd0 2015-11-30 stephen.d return "Twalk"
66 4b33cdd0 2015-11-30 stephen.d case Rwalk:
67 4b33cdd0 2015-11-30 stephen.d return "Rwalk"
68 4b33cdd0 2015-11-30 stephen.d case Topen:
69 4b33cdd0 2015-11-30 stephen.d return "Topen"
70 4b33cdd0 2015-11-30 stephen.d case Ropen:
71 4b33cdd0 2015-11-30 stephen.d return "Ropen"
72 4b33cdd0 2015-11-30 stephen.d case Tcreate:
73 4b33cdd0 2015-11-30 stephen.d return "Tcreate"
74 4b33cdd0 2015-11-30 stephen.d case Rcreate:
75 4b33cdd0 2015-11-30 stephen.d return "Rcreate"
76 4b33cdd0 2015-11-30 stephen.d case Tread:
77 4b33cdd0 2015-11-30 stephen.d return "Tread"
78 4b33cdd0 2015-11-30 stephen.d case Rread:
79 4b33cdd0 2015-11-30 stephen.d return "Rread"
80 4b33cdd0 2015-11-30 stephen.d case Twrite:
81 4b33cdd0 2015-11-30 stephen.d return "Twrite"
82 4b33cdd0 2015-11-30 stephen.d case Rwrite:
83 4b33cdd0 2015-11-30 stephen.d return "Rwrite"
84 4b33cdd0 2015-11-30 stephen.d case Tclunk:
85 4b33cdd0 2015-11-30 stephen.d return "Tclunk"
86 4b33cdd0 2015-11-30 stephen.d case Rclunk:
87 4b33cdd0 2015-11-30 stephen.d return "Rclunk"
88 4b33cdd0 2015-11-30 stephen.d case Tremove:
89 4b33cdd0 2015-11-30 stephen.d return "Tremove"
90 4b33cdd0 2015-11-30 stephen.d case Rremove:
91 4b33cdd0 2015-11-30 stephen.d return "Rremove"
92 4b33cdd0 2015-11-30 stephen.d case Tstat:
93 4b33cdd0 2015-11-30 stephen.d return "Tstat"
94 4b33cdd0 2015-11-30 stephen.d case Rstat:
95 4b33cdd0 2015-11-30 stephen.d return "Rstat"
96 4b33cdd0 2015-11-30 stephen.d case Twstat:
97 4b33cdd0 2015-11-30 stephen.d return "Twstat"
98 4b33cdd0 2015-11-30 stephen.d case Rwstat:
99 4b33cdd0 2015-11-30 stephen.d return "Rwstat"
100 4b33cdd0 2015-11-30 stephen.d default:
101 4b33cdd0 2015-11-30 stephen.d return "Tunknown"
102 4b33cdd0 2015-11-30 stephen.d }
103 4b33cdd0 2015-11-30 stephen.d }
104 4b33cdd0 2015-11-30 stephen.d
105 a0568195 2016-05-23 stevvooe // Fcall defines the fields for sending a 9p formatted message. The type will
106 a0568195 2016-05-23 stevvooe // be introspected from the Message implementation.
107 4b33cdd0 2015-11-30 stephen.d type Fcall struct {
108 4b33cdd0 2015-11-30 stephen.d Type FcallType
109 4b33cdd0 2015-11-30 stephen.d Tag Tag
110 4b33cdd0 2015-11-30 stephen.d Message Message
111 4b33cdd0 2015-11-30 stephen.d }
112 4b33cdd0 2015-11-30 stephen.d
113 4b33cdd0 2015-11-30 stephen.d func newFcall(tag Tag, msg Message) *Fcall {
114 4b33cdd0 2015-11-30 stephen.d return &Fcall{
115 4b33cdd0 2015-11-30 stephen.d Type: msg.Type(),
116 4b33cdd0 2015-11-30 stephen.d Tag: tag,
117 4b33cdd0 2015-11-30 stephen.d Message: msg,
118 4b33cdd0 2015-11-30 stephen.d }
119 4b33cdd0 2015-11-30 stephen.d }
120 4b33cdd0 2015-11-30 stephen.d
121 4b33cdd0 2015-11-30 stephen.d func newErrorFcall(tag Tag, err error) *Fcall {
122 4b33cdd0 2015-11-30 stephen.d var msg Message
123 4b33cdd0 2015-11-30 stephen.d
124 4b33cdd0 2015-11-30 stephen.d switch v := err.(type) {
125 4b33cdd0 2015-11-30 stephen.d case MessageRerror:
126 4b33cdd0 2015-11-30 stephen.d msg = v
127 4b33cdd0 2015-11-30 stephen.d case *MessageRerror:
128 4b33cdd0 2015-11-30 stephen.d msg = *v
129 4b33cdd0 2015-11-30 stephen.d default:
130 4b33cdd0 2015-11-30 stephen.d msg = MessageRerror{Ename: v.Error()}
131 4b33cdd0 2015-11-30 stephen.d }
132 4b33cdd0 2015-11-30 stephen.d
133 4b33cdd0 2015-11-30 stephen.d return &Fcall{
134 4b33cdd0 2015-11-30 stephen.d Type: Rerror,
135 4b33cdd0 2015-11-30 stephen.d Tag: tag,
136 4b33cdd0 2015-11-30 stephen.d Message: msg,
137 4b33cdd0 2015-11-30 stephen.d }
138 4b33cdd0 2015-11-30 stephen.d }
139 4b33cdd0 2015-11-30 stephen.d
140 4b33cdd0 2015-11-30 stephen.d func (fc *Fcall) String() string {
141 4b33cdd0 2015-11-30 stephen.d return fmt.Sprintf("%v(%v) %v", fc.Type, fc.Tag, string9p(fc.Message))
142 4b33cdd0 2015-11-30 stephen.d }