forked from tormoder/fit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_types.go
135 lines (120 loc) · 1.83 KB
/
base_types.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package fit
const baseTypeNumMask = 0x1F
type fitBaseType byte
const (
fitEnum fitBaseType = 0x00
fitSint8 fitBaseType = 0x01 // 2's complement format
fitUint8 fitBaseType = 0x02
fitSint16 fitBaseType = 0x83 // 2's complement format
fitUint16 fitBaseType = 0x84
fitSint32 fitBaseType = 0x85 // 2's complement format
fitUint32 fitBaseType = 0x86
fitString fitBaseType = 0x07 // Null terminated string encoded in UTF-8
fitFloat32 fitBaseType = 0x88
fitFloat64 fitBaseType = 0x89
fitUint8z fitBaseType = 0x0A
fitUint16z fitBaseType = 0x8B
fitUint32z fitBaseType = 0x8C
fitByte fitBaseType = 0x0D // Array of bytes. Field is invalid if all bytes are invalid
)
func (b fitBaseType) nr() int {
return int(b & baseTypeNumMask)
}
func (b fitBaseType) endianAbility() bool {
return bsize[b.nr()] > 0
}
func (b fitBaseType) float() bool {
return !b.integer() && b.signed()
}
func (b fitBaseType) integer() bool {
return binteger[b.nr()]
}
func (b fitBaseType) signed() bool {
return bsigned[b.nr()]
}
func (b fitBaseType) size() int {
return bsize[b.nr()]
}
func (b fitBaseType) String() string {
return bname[b.nr()]
}
var fitBaseTypes = [...]string{
"enum",
"sint8",
"uint8",
"sint16",
"uint16",
"sint32",
"uint32",
"string",
"float32",
"float64",
"uint8z",
"uint16z",
"uint32z",
"byte",
}
var bsize = [...]int{
1,
1,
1,
2,
2,
4,
4,
1,
4,
8,
1,
2,
4,
1,
}
var bname = [...]string{
"enum",
"sint8",
"uint8",
"sint16",
"uint16",
"sint32",
"uint32",
"string",
"float32",
"float64",
"uint8z",
"uint16z",
"uint32z",
"byte",
}
var binteger = [...]bool{
false,
true,
true,
true,
true,
true,
true,
false,
false,
false,
true,
true,
true,
false,
}
var bsigned = [...]bool{
false,
true,
false,
true,
false,
true,
false,
false,
true,
true,
false,
false,
false,
false,
}