/
manifest.go
124 lines (103 loc) · 2.16 KB
/
manifest.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
package proto_reader
import (
"fmt"
"github.com/emicklei/proto"
)
type Option interface {
Name() string
}
type ConstOption struct {
Key string
Value string
}
type ArrayOption struct {
Key string
Value []Option
}
type MapOption struct {
Key string
Value map[string]Option
}
type Field struct {
Name string
Type string
IsRepeated bool
IsMap bool
SubType *string
Comment string
Options []Option
}
func (this *Field) TypeString() string {
if this.IsRepeated {
return fmt.Sprintf("repeated %s", this.Type)
} else if this.IsMap {
return fmt.Sprintf("map<%s, %s>", this.Type, *this.SubType)
} else {
return this.Type
}
}
type EnumEntry struct {
Name string
Index int
}
type Enum struct {
Name string
Items []EnumEntry
}
type Message struct {
Name string
Fields map[string]*Field
Comment string
Options []Option
}
type Method struct {
Name string
Input *Message
Output *Message
StreamingInput bool
StreamingOutput bool
Comment string
Options []Option
}
type Service struct {
Name string
Methods map[string]*Method
Comment string
Options []Option
}
type ProtobufDefinition struct {
Messages map[string]*Message
Services map[string]*Service
Enums map[string]*Enum
Options []Option
}
type ParseResult struct {
Messages map[string]*proto.Message
Services map[string]*proto.Service
Methods map[string]*proto.RPC
Options map[string][]*proto.Option
Enums map[string]*proto.Enum
Imports map[string]*proto.Import
Package string
}
type ProtobufParser interface {
Parse(protoText string) (*ParseResult, error)
}
type ParserFactory = func() ProtobufParser
type ProtobufReader interface {
Read(protoText string) (*ProtobufDefinition, error)
ReadFile(protoFile, importPath string) (*ProtobufDefinition, error)
ReadFileCustom(protoFile, importPath string, fileReader FileReader) (*ProtobufDefinition, error)
}
type FileReader interface {
ReadAll(filePath string) string
}
func (this *ConstOption) Name() string {
return this.Key
}
func (this *ArrayOption) Name() string {
return this.Key
}
func (this *MapOption) Name() string {
return this.Key
}