1 4b33cdd0 2015-11-30 stephen.d package p9p
3 4b33cdd0 2015-11-30 stephen.d import "fmt"
5 4b33cdd0 2015-11-30 stephen.d type FcallType uint8
8 4b33cdd0 2015-11-30 stephen.d Tversion FcallType = iota + 100
9 4b33cdd0 2015-11-30 stephen.d Rversion
12 4b33cdd0 2015-11-30 stephen.d Tattach
13 4b33cdd0 2015-11-30 stephen.d Rattach
22 4b33cdd0 2015-11-30 stephen.d Tcreate
23 4b33cdd0 2015-11-30 stephen.d Rcreate
30 4b33cdd0 2015-11-30 stephen.d Tremove
31 4b33cdd0 2015-11-30 stephen.d Rremove
39 4b33cdd0 2015-11-30 stephen.d func (fct FcallType) String() string {
40 4b33cdd0 2015-11-30 stephen.d switch fct {
41 4b33cdd0 2015-11-30 stephen.d case Tversion:
42 4b33cdd0 2015-11-30 stephen.d return "Tversion"
43 4b33cdd0 2015-11-30 stephen.d case Rversion:
44 4b33cdd0 2015-11-30 stephen.d return "Rversion"
45 4b33cdd0 2015-11-30 stephen.d case Tauth:
46 4b33cdd0 2015-11-30 stephen.d return "Tauth"
47 4b33cdd0 2015-11-30 stephen.d case Rauth:
48 4b33cdd0 2015-11-30 stephen.d return "Rauth"
49 4b33cdd0 2015-11-30 stephen.d case Tattach:
50 4b33cdd0 2015-11-30 stephen.d return "Tattach"
51 4b33cdd0 2015-11-30 stephen.d case Rattach:
52 4b33cdd0 2015-11-30 stephen.d return "Rattach"
53 4b33cdd0 2015-11-30 stephen.d case Terror:
54 4b33cdd0 2015-11-30 stephen.d // invalid.
55 4b33cdd0 2015-11-30 stephen.d return "Terror"
56 4b33cdd0 2015-11-30 stephen.d case Rerror:
57 4b33cdd0 2015-11-30 stephen.d return "Rerror"
58 4b33cdd0 2015-11-30 stephen.d case Tflush:
59 4b33cdd0 2015-11-30 stephen.d return "Tflush"
60 4b33cdd0 2015-11-30 stephen.d case Rflush:
61 4b33cdd0 2015-11-30 stephen.d return "Rflush"
62 4b33cdd0 2015-11-30 stephen.d case Twalk:
63 4b33cdd0 2015-11-30 stephen.d return "Twalk"
64 4b33cdd0 2015-11-30 stephen.d case Rwalk:
65 4b33cdd0 2015-11-30 stephen.d return "Rwalk"
66 4b33cdd0 2015-11-30 stephen.d case Topen:
67 4b33cdd0 2015-11-30 stephen.d return "Topen"
68 4b33cdd0 2015-11-30 stephen.d case Ropen:
69 4b33cdd0 2015-11-30 stephen.d return "Ropen"
70 4b33cdd0 2015-11-30 stephen.d case Tcreate:
71 4b33cdd0 2015-11-30 stephen.d return "Tcreate"
72 4b33cdd0 2015-11-30 stephen.d case Rcreate:
73 4b33cdd0 2015-11-30 stephen.d return "Rcreate"
74 4b33cdd0 2015-11-30 stephen.d case Tread:
75 4b33cdd0 2015-11-30 stephen.d return "Tread"
76 4b33cdd0 2015-11-30 stephen.d case Rread:
77 4b33cdd0 2015-11-30 stephen.d return "Rread"
78 4b33cdd0 2015-11-30 stephen.d case Twrite:
79 4b33cdd0 2015-11-30 stephen.d return "Twrite"
80 4b33cdd0 2015-11-30 stephen.d case Rwrite:
81 4b33cdd0 2015-11-30 stephen.d return "Rwrite"
82 4b33cdd0 2015-11-30 stephen.d case Tclunk:
83 4b33cdd0 2015-11-30 stephen.d return "Tclunk"
84 4b33cdd0 2015-11-30 stephen.d case Rclunk:
85 4b33cdd0 2015-11-30 stephen.d return "Rclunk"
86 4b33cdd0 2015-11-30 stephen.d case Tremove:
87 4b33cdd0 2015-11-30 stephen.d return "Tremove"
88 4b33cdd0 2015-11-30 stephen.d case Rremove:
89 4b33cdd0 2015-11-30 stephen.d return "Rremove"
90 4b33cdd0 2015-11-30 stephen.d case Tstat:
91 4b33cdd0 2015-11-30 stephen.d return "Tstat"
92 4b33cdd0 2015-11-30 stephen.d case Rstat:
93 4b33cdd0 2015-11-30 stephen.d return "Rstat"
94 4b33cdd0 2015-11-30 stephen.d case Twstat:
95 4b33cdd0 2015-11-30 stephen.d return "Twstat"
96 4b33cdd0 2015-11-30 stephen.d case Rwstat:
97 4b33cdd0 2015-11-30 stephen.d return "Rwstat"
98 4b33cdd0 2015-11-30 stephen.d default:
99 4b33cdd0 2015-11-30 stephen.d return "Tunknown"
103 4b33cdd0 2015-11-30 stephen.d type Fcall struct {
104 4b33cdd0 2015-11-30 stephen.d Type FcallType
105 4b33cdd0 2015-11-30 stephen.d Tag Tag
106 4b33cdd0 2015-11-30 stephen.d Message Message
109 4b33cdd0 2015-11-30 stephen.d func newFcall(tag Tag, msg Message) *Fcall {
110 4b33cdd0 2015-11-30 stephen.d switch msg.Type() {
111 4b33cdd0 2015-11-30 stephen.d case Tversion, Rversion:
112 4b33cdd0 2015-11-30 stephen.d tag = NOTAG
115 4b33cdd0 2015-11-30 stephen.d return &Fcall{
116 4b33cdd0 2015-11-30 stephen.d Type: msg.Type(),
117 4b33cdd0 2015-11-30 stephen.d Tag: tag,
118 4b33cdd0 2015-11-30 stephen.d Message: msg,
122 4b33cdd0 2015-11-30 stephen.d func newErrorFcall(tag Tag, err error) *Fcall {
123 4b33cdd0 2015-11-30 stephen.d var msg Message
125 4b33cdd0 2015-11-30 stephen.d switch v := err.(type) {
126 4b33cdd0 2015-11-30 stephen.d case MessageRerror:
127 4b33cdd0 2015-11-30 stephen.d msg = v
128 4b33cdd0 2015-11-30 stephen.d case *MessageRerror:
129 4b33cdd0 2015-11-30 stephen.d msg = *v
130 4b33cdd0 2015-11-30 stephen.d default:
131 4b33cdd0 2015-11-30 stephen.d msg = MessageRerror{Ename: v.Error()}
134 4b33cdd0 2015-11-30 stephen.d return &Fcall{
135 4b33cdd0 2015-11-30 stephen.d Type: Rerror,
136 4b33cdd0 2015-11-30 stephen.d Tag: tag,
137 4b33cdd0 2015-11-30 stephen.d Message: msg,
141 4b33cdd0 2015-11-30 stephen.d func (fc *Fcall) String() string {
142 4b33cdd0 2015-11-30 stephen.d return fmt.Sprintf("%v(%v) %v", fc.Type, fc.Tag, string9p(fc.Message))