forked from lyft/protoc-gen-star
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethod.go
84 lines (63 loc) · 2.75 KB
/
method.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
package pgs
import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
)
// Method describes a method on a proto service
type Method interface {
Entity
// Descriptor returns the underlying proto descriptor for this.
Descriptor() *descriptor.MethodDescriptorProto
// Service returns the parent service for this.
Service() Service
// Input returns the Message representing the input type for this.
Input() Message
// Output returns the Message representing this output type for this.
Output() Message
// ClientStreaming indicates if this method allows clients to stream inputs
ClientStreaming() bool
// ServerStreaming indicates if this method allows servers to stream outputs
ServerStreaming() bool
setService(Service)
}
type method struct {
desc *descriptor.MethodDescriptorProto
service Service
in, out Message
comments string
}
func (m *method) Name() Name { return Name(m.desc.GetName()) }
func (m *method) FullyQualifiedName() string { return fullyQualifiedName(m.service, m) }
func (m *method) Syntax() Syntax { return m.service.Syntax() }
func (m *method) Package() Package { return m.service.Package() }
func (m *method) File() File { return m.service.File() }
func (m *method) BuildTarget() bool { return m.service.BuildTarget() }
func (m *method) Comments() string { return m.comments }
func (m *method) Descriptor() *descriptor.MethodDescriptorProto { return m.desc }
func (m *method) Service() Service { return m.service }
func (m *method) Input() Message { return m.in }
func (m *method) Output() Message { return m.out }
func (m *method) ClientStreaming() bool { return m.desc.GetClientStreaming() }
func (m *method) ServerStreaming() bool { return m.desc.GetServerStreaming() }
func (m *method) BiDirStreaming() bool { return m.ClientStreaming() && m.ServerStreaming() }
func (m *method) Imports() (i []Package) {
mine := m.Package().GoName()
if input := m.Input().Package(); mine != input.GoName() {
i = append(i, input)
}
if output := m.Output().Package(); mine != output.GoName() {
i = append(i, output)
}
return
}
func (m *method) Extension(desc *proto.ExtensionDesc, ext interface{}) (ok bool, err error) {
return extension(m.desc.GetOptions(), desc, &ext)
}
func (m *method) accept(v Visitor) (err error) {
if v == nil {
return
}
_, err = v.VisitMethod(m)
return
}
func (m *method) setService(s Service) { m.service = s }