generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
map.go
47 lines (38 loc) · 1.08 KB
/
map.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
package schema
import (
"fmt"
"google.golang.org/protobuf/proto"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)
type Map struct {
Pos Position `parser:"" protobuf:"1,optional"`
Key Type `parser:"'{' @@" protobuf:"2"`
Value Type `parser:"':' @@ '}'" protobuf:"3"`
}
var _ Type = (*Map)(nil)
var _ Symbol = (*Map)(nil)
func (m *Map) Equal(other Type) bool {
o, ok := other.(*Map)
if !ok {
return false
}
return m.Key.Equal(o.Key) && m.Value.Equal(o.Value)
}
func (m *Map) Position() Position { return m.Pos }
func (m *Map) schemaChildren() []Node { return []Node{m.Key, m.Value} }
func (*Map) schemaType() {}
func (*Map) schemaSymbol() {}
func (m *Map) String() string { return fmt.Sprintf("{%s: %s}", m.Key.String(), m.Value.String()) }
func (m *Map) ToProto() proto.Message {
return &schemapb.Map{
Key: TypeToProto(m.Key),
Value: TypeToProto(m.Value),
}
}
func mapToSchema(s *schemapb.Map) *Map {
return &Map{
Pos: posFromProto(s.Pos),
Key: TypeFromProto(s.Key),
Value: TypeFromProto(s.Value),
}
}