forked from ipld/go-ipld-prime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_map.go
55 lines (42 loc) · 1.18 KB
/
type_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
48
49
50
51
52
53
54
55
package schema
import (
"github.com/ipld/go-ipld-prime"
schemadmt "github.com/ipld/go-ipld-prime/schema/dmt"
)
type TypeMap struct {
name TypeName
dmt schemadmt.TypeMap
ts *TypeSystem
}
// -- schema.Type interface satisfaction -->
var _ Type = (*TypeMap)(nil)
func (t *TypeMap) _Type() {}
func (t *TypeMap) TypeSystem() *TypeSystem {
return t.ts
}
func (TypeMap) TypeKind() TypeKind {
return TypeKind_Map
}
func (t *TypeMap) Name() TypeName {
return t.name
}
func (t TypeMap) RepresentationBehavior() ipld.Kind {
return ipld.Kind_Map
}
// -- specific to TypeMap -->
// KeyType returns the Type of the map keys.
//
// Note that map keys will must always be some type which is representable as a
// string in the IPLD Data Model (e.g. either TypeString or TypeEnum).
func (t *TypeMap) KeyType() Type {
return t.ts.types[t.dmt.FieldKeyType().TypeReference()]
}
// ValueType returns the Type of the map values.
func (t *TypeMap) ValueType() Type {
return t.ts.types[t.dmt.FieldValueType().TypeReference()]
}
// ValueIsNullable returns a bool describing if the map values are permitted
// to be null.
func (t *TypeMap) ValueIsNullable() bool {
return t.dmt.FieldValueNullable().Bool()
}