Blob


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