1 8a7ec697 2015-10-26 adrien package p9pnew
3 499f8c59 2015-10-27 stephen.d import "fmt"
5 8a7ec697 2015-10-26 adrien type FcallType uint8
8 8a7ec697 2015-10-26 adrien Tversion FcallType = iota + 100
39 499f8c59 2015-10-27 stephen.d func (fct FcallType) String() string {
40 499f8c59 2015-10-27 stephen.d switch fct {
41 499f8c59 2015-10-27 stephen.d case Tversion:
42 499f8c59 2015-10-27 stephen.d return "Tversion"
43 499f8c59 2015-10-27 stephen.d case Rversion:
44 499f8c59 2015-10-27 stephen.d return "Rversion"
45 499f8c59 2015-10-27 stephen.d case Tauth:
46 499f8c59 2015-10-27 stephen.d return "Tauth"
47 499f8c59 2015-10-27 stephen.d case Rauth:
48 499f8c59 2015-10-27 stephen.d return "Rauth"
49 499f8c59 2015-10-27 stephen.d case Tattach:
50 499f8c59 2015-10-27 stephen.d return "Tattach"
51 499f8c59 2015-10-27 stephen.d case Rattach:
52 499f8c59 2015-10-27 stephen.d return "Rattach"
53 499f8c59 2015-10-27 stephen.d case Terror:
54 499f8c59 2015-10-27 stephen.d // invalid.
55 499f8c59 2015-10-27 stephen.d return "Terror"
56 499f8c59 2015-10-27 stephen.d case Rerror:
57 499f8c59 2015-10-27 stephen.d return "Rerror"
58 499f8c59 2015-10-27 stephen.d case Tflush:
59 499f8c59 2015-10-27 stephen.d return "Tflush"
60 499f8c59 2015-10-27 stephen.d case Rflush:
61 499f8c59 2015-10-27 stephen.d return "Rflush"
62 499f8c59 2015-10-27 stephen.d case Twalk:
63 499f8c59 2015-10-27 stephen.d return "Twalk"
64 499f8c59 2015-10-27 stephen.d case Rwalk:
65 499f8c59 2015-10-27 stephen.d return "Rwalk"
66 499f8c59 2015-10-27 stephen.d case Topen:
67 499f8c59 2015-10-27 stephen.d return "Topen"
68 499f8c59 2015-10-27 stephen.d case Ropen:
69 499f8c59 2015-10-27 stephen.d return "Ropen"
70 499f8c59 2015-10-27 stephen.d case Tcreate:
71 499f8c59 2015-10-27 stephen.d return "Tcreate"
72 499f8c59 2015-10-27 stephen.d case Rcreate:
73 499f8c59 2015-10-27 stephen.d return "Rcreate"
74 499f8c59 2015-10-27 stephen.d case Tread:
75 499f8c59 2015-10-27 stephen.d return "Tread"
76 499f8c59 2015-10-27 stephen.d case Rread:
77 499f8c59 2015-10-27 stephen.d return "Rread"
78 499f8c59 2015-10-27 stephen.d case Twrite:
79 499f8c59 2015-10-27 stephen.d return "Twrite"
80 499f8c59 2015-10-27 stephen.d case Rwrite:
81 499f8c59 2015-10-27 stephen.d return "Rwrite"
82 499f8c59 2015-10-27 stephen.d case Tclunk:
83 499f8c59 2015-10-27 stephen.d return "Tclunk"
84 499f8c59 2015-10-27 stephen.d case Rclunk:
85 499f8c59 2015-10-27 stephen.d return "Rclunk"
86 499f8c59 2015-10-27 stephen.d case Tremove:
87 499f8c59 2015-10-27 stephen.d return "Tremote"
88 499f8c59 2015-10-27 stephen.d case Rremove:
89 499f8c59 2015-10-27 stephen.d return "Rremove"
90 499f8c59 2015-10-27 stephen.d case Tstat:
91 499f8c59 2015-10-27 stephen.d return "Tstat"
92 499f8c59 2015-10-27 stephen.d case Rstat:
93 499f8c59 2015-10-27 stephen.d return "Rstat"
94 499f8c59 2015-10-27 stephen.d case Twstat:
95 499f8c59 2015-10-27 stephen.d return "Twstat"
96 499f8c59 2015-10-27 stephen.d case Rwstat:
97 499f8c59 2015-10-27 stephen.d return "Rwstat"
98 499f8c59 2015-10-27 stephen.d default:
99 499f8c59 2015-10-27 stephen.d return "Tunknown"
103 8a7ec697 2015-10-26 adrien type Fcall struct {
104 499f8c59 2015-10-27 stephen.d Type FcallType
106 8a7ec697 2015-10-26 adrien Message Message
109 e6bcde66 2015-10-29 stephen.d func newFcall(msg Message) *Fcall {
110 74ec7ac9 2015-10-30 stephen.d var tag Tag
112 f9cc2426 2015-11-05 stephen.d switch msg.Type() {
113 74ec7ac9 2015-10-30 stephen.d case Tversion, Rversion:
114 74ec7ac9 2015-10-30 stephen.d tag = NOTAG
117 e6bcde66 2015-10-29 stephen.d return &Fcall{
118 f9cc2426 2015-11-05 stephen.d Type: msg.Type(),
119 74ec7ac9 2015-10-30 stephen.d Tag: tag,
120 e6bcde66 2015-10-29 stephen.d Message: msg,
124 40d4a02d 2015-11-03 stephen.d func newErrorFcall(tag Tag, err error) *Fcall {
125 40d4a02d 2015-11-03 stephen.d var msg Message
127 40d4a02d 2015-11-03 stephen.d switch v := err.(type) {
128 40d4a02d 2015-11-03 stephen.d case MessageRerror:
129 40d4a02d 2015-11-03 stephen.d msg = v
130 40d4a02d 2015-11-03 stephen.d case *MessageRerror:
131 269e4d4b 2015-11-05 stephen.d msg = *v
132 40d4a02d 2015-11-03 stephen.d default:
133 40d4a02d 2015-11-03 stephen.d msg = MessageRerror{Ename: v.Error()}
136 40d4a02d 2015-11-03 stephen.d return &Fcall{
137 40d4a02d 2015-11-03 stephen.d Type: Rerror,
138 40d4a02d 2015-11-03 stephen.d Tag: tag,
139 40d4a02d 2015-11-03 stephen.d Message: msg,
143 e6bcde66 2015-10-29 stephen.d func (fc *Fcall) String() string {
144 74ec7ac9 2015-10-30 stephen.d return fmt.Sprintf("%v(%v) %v", fc.Type, fc.Tag, string9p(fc.Message))