-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenum.go
35 lines (29 loc) · 876 Bytes
/
enum.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
package protostub
import (
"github.com/emicklei/proto"
)
// EnumVisitor is the Visitor for an enum, created by the main visitor. It
// contains an Enum with all the type data - see types.go.
type EnumVisitor struct {
ProtoData
Enum Enum
}
// NewEnumVisitor creates a new EnumVisitor
func NewEnumVisitor() *EnumVisitor {
return &EnumVisitor{
ProtoData: ProtoData{},
}
}
// VisitEnumField creates an enum field to the member list
func (ev *EnumVisitor) VisitEnumField(e *proto.EnumField) {
// using the Any type because of this:
// https://github.com/python/typeshed/blob/master/stdlib/3.4/enum.pyi#L31
ev.Enum.Members = append(ev.Enum.Members, Member{e.Name, "Any", nil})
}
// VisitEnum will set the correct name and visit the elements
func (ev *EnumVisitor) VisitEnum(e *proto.Enum) {
ev.Enum.name = e.Name
for _, i := range e.Elements {
i.Accept(ev)
}
}