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