1
|
|
|
/* |
2
|
|
|
* byte-data: Pack and unpack binary data. |
3
|
|
|
* https://github.com/rochars/byte-data |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017-2018 Rafael da Silva Rocha. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining |
8
|
|
|
* a copy of this software and associated documentation files (the |
9
|
|
|
* "Software"), to deal in the Software without restriction, including |
10
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, |
11
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to |
12
|
|
|
* permit persons to whom the Software is furnished to do so, subject to |
13
|
|
|
* the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be |
16
|
|
|
* included in all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
19
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
20
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
21
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
22
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
23
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
24
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @fileoverview Standard type definitions. |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
/** @module byteData/types */ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* byte-data standard types. |
36
|
|
|
* @type {!Object} |
37
|
|
|
*/ |
38
|
|
|
export const types = { |
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* A char. |
42
|
|
|
* @type {!Object} |
43
|
|
|
* @export |
44
|
|
|
*/ |
45
|
|
|
chr: {'bits': 8, 'char': true}, |
46
|
|
|
/** |
47
|
|
|
* A 4-char string |
48
|
|
|
* @type {!Object} |
49
|
|
|
* @export |
50
|
|
|
*/ |
51
|
|
|
fourCC: {'bits': 32, 'char': true}, |
52
|
|
|
/** |
53
|
|
|
* Booleans |
54
|
|
|
* @type {!Object} |
55
|
|
|
* @export |
56
|
|
|
*/ |
57
|
|
|
bool: {'bits': 1}, |
58
|
|
|
/** |
59
|
|
|
* Signed 2-bit integers |
60
|
|
|
* @type {!Object} |
61
|
|
|
* @export |
62
|
|
|
*/ |
63
|
|
|
int2: {'bits': 2, 'signed': true}, |
64
|
|
|
/** |
65
|
|
|
* Unsigned 2-bit integers |
66
|
|
|
* @type {!Object} |
67
|
|
|
* @export |
68
|
|
|
*/ |
69
|
|
|
uInt2: {'bits': 2}, |
70
|
|
|
/** |
71
|
|
|
* Signed 4-bit integers |
72
|
|
|
* @type {!Object} |
73
|
|
|
* @export |
74
|
|
|
*/ |
75
|
|
|
int4: {'bits': 4, 'signed': true}, |
76
|
|
|
/** |
77
|
|
|
* Unsigned 4-bit integers |
78
|
|
|
* @type {!Object} |
79
|
|
|
* @export |
80
|
|
|
*/ |
81
|
|
|
uInt4: {'bits': 4}, |
82
|
|
|
/** |
83
|
|
|
* Signed 8-bit integers |
84
|
|
|
* @type {!Object} |
85
|
|
|
* @export |
86
|
|
|
*/ |
87
|
|
|
int8: {'bits': 8, 'signed': true}, |
88
|
|
|
/** |
89
|
|
|
* Unsigned 4-bit integers |
90
|
|
|
* @type {!Object} |
91
|
|
|
* @export |
92
|
|
|
*/ |
93
|
|
|
uInt8: {'bits': 8}, |
94
|
|
|
// LE |
95
|
|
|
/** |
96
|
|
|
* Signed 16-bit integers little-endian |
97
|
|
|
* @type {!Object} |
98
|
|
|
* @export |
99
|
|
|
*/ |
100
|
|
|
int16 : {'bits': 16, 'signed': true}, |
101
|
|
|
/** |
102
|
|
|
* Unsigned 16-bit integers little-endian |
103
|
|
|
* @type {!Object} |
104
|
|
|
* @export |
105
|
|
|
*/ |
106
|
|
|
uInt16: {'bits': 16}, |
107
|
|
|
/** |
108
|
|
|
* Half-precision floating-point numbers little-endian |
109
|
|
|
* @type {!Object} |
110
|
|
|
* @export |
111
|
|
|
*/ |
112
|
|
|
float16: {'bits': 16, 'float': true}, |
113
|
|
|
/** |
114
|
|
|
* Signed 24-bit integers little-endian |
115
|
|
|
* @type {!Object} |
116
|
|
|
* @export |
117
|
|
|
*/ |
118
|
|
|
int24: {'bits': 24, 'signed': true}, |
119
|
|
|
/** |
120
|
|
|
* Unsigned 24-bit integers little-endian |
121
|
|
|
* @type {!Object} |
122
|
|
|
* @export |
123
|
|
|
*/ |
124
|
|
|
uInt24: {'bits': 24}, |
125
|
|
|
/** |
126
|
|
|
* Signed 32-bit integers little-endian |
127
|
|
|
* @type {!Object} |
128
|
|
|
* @export |
129
|
|
|
*/ |
130
|
|
|
int32: {'bits': 32, 'signed': true}, |
131
|
|
|
/** |
132
|
|
|
* Unsigned 32-bit integers little-endian |
133
|
|
|
* @type {!Object} |
134
|
|
|
* @export |
135
|
|
|
*/ |
136
|
|
|
uInt32: {'bits': 32}, |
137
|
|
|
/** |
138
|
|
|
* Single-precision floating-point numbers little-endian |
139
|
|
|
* @type {!Object} |
140
|
|
|
* @export |
141
|
|
|
*/ |
142
|
|
|
float32: {'bits': 32, 'float': true}, |
143
|
|
|
/** |
144
|
|
|
* Signed 40-bit integers little-endian |
145
|
|
|
* @type {!Object} |
146
|
|
|
* @export |
147
|
|
|
*/ |
148
|
|
|
int40: {'bits': 40, 'signed': true}, |
149
|
|
|
/** |
150
|
|
|
* Unsigned 40-bit integers little-endian |
151
|
|
|
* @type {!Object} |
152
|
|
|
* @export |
153
|
|
|
*/ |
154
|
|
|
uInt40: {'bits': 40}, |
155
|
|
|
/** |
156
|
|
|
* Signed 48-bit integers little-endian |
157
|
|
|
* @type {!Object} |
158
|
|
|
* @export |
159
|
|
|
*/ |
160
|
|
|
int48: {'bits': 48, 'signed': true}, |
161
|
|
|
/** |
162
|
|
|
* Unsigned 48-bit integers little-endian |
163
|
|
|
* @type {!Object} |
164
|
|
|
* @export |
165
|
|
|
*/ |
166
|
|
|
uInt48: {'bits': 48}, |
167
|
|
|
/** |
168
|
|
|
* Double-precision floating-point numbers little-endian |
169
|
|
|
* @type {!Object} |
170
|
|
|
* @export |
171
|
|
|
*/ |
172
|
|
|
float64: {'bits': 64, 'float': true}, |
173
|
|
|
// BE |
174
|
|
|
/** |
175
|
|
|
* Signed 16-bit integers big-endian |
176
|
|
|
* @type {!Object} |
177
|
|
|
* @export |
178
|
|
|
*/ |
179
|
|
|
int16BE : {'bits': 16, 'signed': true, 'be': true}, |
180
|
|
|
/** |
181
|
|
|
* Unsigned 16-bit integers big-endian |
182
|
|
|
* @type {!Object} |
183
|
|
|
* @export |
184
|
|
|
*/ |
185
|
|
|
uInt16BE: {'bits': 16, 'be': true}, |
186
|
|
|
/** |
187
|
|
|
* Half-precision floating-point numbers big-endian |
188
|
|
|
* @type {!Object} |
189
|
|
|
* @export |
190
|
|
|
*/ |
191
|
|
|
float16BE: {'bits': 16, 'float': true, 'be': true}, |
192
|
|
|
/** |
193
|
|
|
* Signed 24-bit integers big-endian |
194
|
|
|
* @type {!Object} |
195
|
|
|
* @export |
196
|
|
|
*/ |
197
|
|
|
int24BE: {'bits': 24, 'signed': true, 'be': true}, |
198
|
|
|
/** |
199
|
|
|
* Unsigned 24-bit integers big-endian |
200
|
|
|
* @type {!Object} |
201
|
|
|
* @export |
202
|
|
|
*/ |
203
|
|
|
uInt24BE: {'bits': 24, 'be': true}, |
204
|
|
|
/** |
205
|
|
|
* Signed 32-bit integers big-endian |
206
|
|
|
* @type {!Object} |
207
|
|
|
* @export |
208
|
|
|
*/ |
209
|
|
|
int32BE: {'bits': 32, 'signed': true, 'be': true}, |
210
|
|
|
/** |
211
|
|
|
* Unsigned 32-bit integers big-endian |
212
|
|
|
* @type {!Object} |
213
|
|
|
* @export |
214
|
|
|
*/ |
215
|
|
|
uInt32BE: {'bits': 32, 'be': true}, |
216
|
|
|
/** |
217
|
|
|
* Single-precision floating-point numbers big-endian |
218
|
|
|
* @type {!Object} |
219
|
|
|
* @export |
220
|
|
|
*/ |
221
|
|
|
float32BE: {'bits': 32, 'float': true, 'be': true}, |
222
|
|
|
/** |
223
|
|
|
* Signed 40-bit integers big-endian |
224
|
|
|
* @type {!Object} |
225
|
|
|
* @export |
226
|
|
|
*/ |
227
|
|
|
int40BE: {'bits': 40, 'signed': true, 'be': true}, |
228
|
|
|
/** |
229
|
|
|
* Unsigned 40-bit integers big-endian |
230
|
|
|
* @type {!Object} |
231
|
|
|
* @export |
232
|
|
|
*/ |
233
|
|
|
uInt40BE: {'bits': 40, 'be': true}, |
234
|
|
|
/** |
235
|
|
|
* Signed 48-bit integers big-endian |
236
|
|
|
* @type {!Object} |
237
|
|
|
* @export |
238
|
|
|
*/ |
239
|
|
|
int48BE: {'bits': 48, 'signed': true, 'be': true}, |
240
|
|
|
/** |
241
|
|
|
* Unsigned 48-bit integers big-endian |
242
|
|
|
* @type {!Object} |
243
|
|
|
* @export |
244
|
|
|
*/ |
245
|
|
|
uInt48BE: {'bits': 48, 'be': true}, |
246
|
|
|
/** |
247
|
|
|
* Double-precision floating-point numbers big-endian |
248
|
|
|
* @type {!Object} |
249
|
|
|
* @export |
250
|
|
|
*/ |
251
|
|
|
float64BE: {'bits': 64, 'float': true, 'be': true}, |
252
|
|
|
}; |
253
|
|
|
|