generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
topic.go
66 lines (54 loc) · 1.43 KB
/
topic.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
package schema
import (
"fmt"
"strings"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"google.golang.org/protobuf/proto"
)
type Topic struct {
Pos Position `parser:"" protobuf:"1,optional"`
Comments []string `parser:"@Comment*" protobuf:"2"`
Export bool `parser:"@'export'?" protobuf:"3"`
Name string `parser:"'topic' @Ident" protobuf:"4"`
Event Type `parser:"@@" protobuf:"5"`
}
var _ Decl = (*Topic)(nil)
var _ Symbol = (*Topic)(nil)
func (t *Topic) Position() Position { return t.Pos }
func (*Topic) schemaDecl() {}
func (*Topic) schemaSymbol() {}
func (t *Topic) schemaChildren() []Node {
if t.Event == nil {
return nil
}
return []Node{t.Event}
}
func (t *Topic) GetName() string { return t.Name }
func (t *Topic) IsExported() bool { return t.Export }
func (t *Topic) String() string {
w := &strings.Builder{}
fmt.Fprint(w, EncodeComments(t.Comments))
if t.Export {
fmt.Fprint(w, "export ")
}
fmt.Fprintf(w, "topic %s %s", t.Name, t.Event)
return w.String()
}
func (t *Topic) ToProto() proto.Message {
return &schemapb.Topic{
Pos: posToProto(t.Pos),
Name: t.Name,
Export: t.Export,
Event: TypeToProto(t.Event),
Comments: t.Comments,
}
}
func TopicFromProto(t *schemapb.Topic) *Topic {
return &Topic{
Pos: posFromProto(t.Pos),
Name: t.Name,
Export: t.Export,
Event: TypeFromProto(t.Event),
Comments: t.Comments,
}
}