/
noms_kind.go
72 lines (61 loc) · 1.61 KB
/
noms_kind.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
67
68
69
70
71
72
// Copyright 2016 Attic Labs, Inc. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package types
// NomsKind allows a TypeDesc to indicate what kind of type is described.
type NomsKind uint8
// All supported kinds of Noms types are enumerated here.
// The ordering of these (especially Bool, Number and String) is important for ordering of values.
const (
BoolKind NomsKind = iota
NumberKind
StringKind
BlobKind
ValueKind
ListKind
MapKind
RefKind
SetKind
// Keep StructKind and CycleKind together.
StructKind
CycleKind
TypeKind
UnionKind
// Internal to decoder
hashKind
)
var KindToString = map[NomsKind]string{
BlobKind: "Blob",
BoolKind: "Bool",
CycleKind: "Cycle",
ListKind: "List",
MapKind: "Map",
NumberKind: "Number",
RefKind: "Ref",
SetKind: "Set",
StructKind: "Struct",
StringKind: "String",
TypeKind: "Type",
UnionKind: "Union",
ValueKind: "Value",
}
// String returns the name of the kind.
func (k NomsKind) String() string {
return KindToString[k]
}
// IsPrimitiveKind returns true if k represents a Noms primitive type, which excludes collections (List, Map, Set), Refs, Structs, Symbolic and Unresolved types.
func IsPrimitiveKind(k NomsKind) bool {
switch k {
case BoolKind, NumberKind, StringKind, BlobKind, ValueKind, TypeKind:
return true
default:
return false
}
}
// isKindOrderedByValue determines if a value is ordered by its value instead of its hash.
func isKindOrderedByValue(k NomsKind) bool {
return k <= StringKind
}
func (k NomsKind) writeTo(w nomsWriter) {
w.writeUint8(uint8(k))
}