File: method.go

package info (click to toggle)
golang-github-lyft-protoc-gen-star 2.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 940 kB
  • sloc: makefile: 145
file content (96 lines) | stat: -rw-r--r-- 3,043 bytes parent folder | download | duplicates (2)
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
package pgs

import (
	"google.golang.org/protobuf/runtime/protoimpl"
	descriptor "google.golang.org/protobuf/types/descriptorpb"
)

// 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 the 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
	fqn     string
	service Service

	in, out Message

	info SourceCodeInfo
}

func (m *method) Name() Name                                    { return Name(m.desc.GetName()) }
func (m *method) FullyQualifiedName() string                    { return m.fqn }
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) SourceCodeInfo() SourceCodeInfo                { return m.info }
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 []File) {
	mine := m.File().Name()
	input := m.Input().File()
	output := m.Output().File()

	if mine != input.Name() {
		i = append(i, input)
	}
	if mine != output.Name() && input.Name() != output.Name() {
		i = append(i, output)
	}
	return
}

func (m *method) Extension(desc *protoimpl.ExtensionInfo, 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 }

func (m *method) childAtPath(path []int32) Entity {
	if len(path) == 0 {
		return m
	}
	return nil
}

func (m *method) addSourceCodeInfo(info SourceCodeInfo) { m.info = info }

var _ Method = (*method)(nil)