/
type_enum.go
66 lines (52 loc) · 1.43 KB
/
type_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
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 (
"github.com/ipld/go-ipld-prime"
schemadmt "github.com/ipld/go-ipld-prime/schema/dmt"
)
type TypeEnum struct {
name TypeName
dmt schemadmt.TypeEnum
ts *TypeSystem
}
type EnumRepresentation interface{ _EnumRepresentation() }
func (EnumRepresentation_String) _EnumRepresentation() {}
func (EnumRepresentation_Int) _EnumRepresentation() {}
type EnumRepresentation_String struct {
dmt schemadmt.EnumRepresentation_String
}
type EnumRepresentation_Int struct {
dmt schemadmt.EnumRepresentation_Int
}
// -- schema.Type interface satisfaction -->
var _ Type = (*TypeEnum)(nil)
func (t *TypeEnum) _Type() {}
func (t *TypeEnum) TypeSystem() *TypeSystem {
return t.ts
}
func (TypeEnum) TypeKind() TypeKind {
return TypeKind_Struct
}
func (t *TypeEnum) Name() TypeName {
return t.name
}
func (t TypeEnum) RepresentationBehavior() ipld.Kind {
switch t.dmt.FieldRepresentation().AsInterface().(type) {
case schemadmt.EnumRepresentation_String:
return ipld.Kind_String
case schemadmt.EnumRepresentation_Int:
return ipld.Kind_Int
default:
panic("unreachable")
}
}
// -- specific to TypeEnum -->
func (t *TypeEnum) RepresentationStrategy() EnumRepresentation {
switch x := t.dmt.FieldRepresentation().AsInterface().(type) {
case schemadmt.EnumRepresentation_String:
return EnumRepresentation_String{x}
case schemadmt.EnumRepresentation_Int:
return EnumRepresentation_Int{x}
default:
panic("unreachable")
}
}