-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
76 lines (67 loc) · 1.4 KB
/
type.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
73
74
75
76
package msgpack
import "fmt"
const (
extTime = -1
)
// Type represents an MessagePack data type.
type Type string
// All supported MessagePack types.
const (
Nil Type = "nil"
Bool Type = "bool"
Int Type = "int"
Uint Type = "uint"
Float Type = "float"
String Type = "string"
Bytes Type = "bytes"
Array Type = "array"
Map Type = "map"
Ext Type = "ext"
// extension types
Time Type = "time"
)
func extType(typ int8) Type {
if typ == extTime {
return Time
}
return Ext
}
// tagType returns the type for a given tag. For every extension type
// Ext will be returned.
func tagType(tag byte) Type {
switch tag {
case tagNil:
return Nil
case tagFalse, tagTrue:
return Bool
case tagInt8, tagInt16, tagInt32, tagInt64:
return Int
case tagUint8, tagUint16, tagUint32, tagUint64:
return Uint
case tagFloat32, tagFloat64:
return Float
case tagBin8, tagBin16, tagBin32:
return Bytes
case tagStr8, tagStr16, tagStr32:
return String
case tagArray16, tagArray32:
return Array
case tagMap16, tagMap32:
return Map
case tagFixExt1, tagFixExt2, tagFixExt4, tagFixExt8, tagFixExt16, tagExt8, tagExt16, tagExt32:
return Ext
}
switch {
case isPosFixintTag(tag):
return Uint
case isNegFixintTag(tag):
return Int
case isFixstrTag(tag):
return String
case isFixarrayTag(tag):
return Array
case isFixmapTag(tag):
return Map
}
return Type(fmt.Sprintf("%#02x", tag))
}