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
|
|
|
* A char. |
41
|
|
|
* @type {!Object} |
42
|
|
|
* @export |
43
|
|
|
*/ |
44
|
|
|
chr: {'bits': 8, 'char': true}, |
45
|
|
|
/** |
46
|
|
|
* A 4-char string |
47
|
|
|
* @type {!Object} |
48
|
|
|
* @export |
49
|
|
|
*/ |
50
|
|
|
fourCC: {'bits': 32, 'char': true}, |
51
|
|
|
/** |
52
|
|
|
* Booleans |
53
|
|
|
* @type {!Object} |
54
|
|
|
* @export |
55
|
|
|
*/ |
56
|
|
|
bool: {'bits': 1}, |
57
|
|
|
/** |
58
|
|
|
* Signed 2-bit integers |
59
|
|
|
* @type {!Object} |
60
|
|
|
* @export |
61
|
|
|
*/ |
62
|
|
|
int2: {'bits': 2, 'signed': true}, |
63
|
|
|
/** |
64
|
|
|
* Unsigned 2-bit integers |
65
|
|
|
* @type {!Object} |
66
|
|
|
* @export |
67
|
|
|
*/ |
68
|
|
|
uInt2: {'bits': 2}, |
69
|
|
|
/** |
70
|
|
|
* Signed 4-bit integers |
71
|
|
|
* @type {!Object} |
72
|
|
|
* @export |
73
|
|
|
*/ |
74
|
|
|
int4: {'bits': 4, 'signed': true}, |
75
|
|
|
/** |
76
|
|
|
* Unsigned 4-bit integers |
77
|
|
|
* @type {!Object} |
78
|
|
|
* @export |
79
|
|
|
*/ |
80
|
|
|
uInt4: {'bits': 4}, |
81
|
|
|
/** |
82
|
|
|
* Signed 8-bit integers |
83
|
|
|
* @type {!Object} |
84
|
|
|
* @export |
85
|
|
|
*/ |
86
|
|
|
int8: {'bits': 8, 'signed': true}, |
87
|
|
|
/** |
88
|
|
|
* Unsigned 4-bit integers |
89
|
|
|
* @type {!Object} |
90
|
|
|
* @export |
91
|
|
|
*/ |
92
|
|
|
uInt8: {'bits': 8}, |
93
|
|
|
// LE |
94
|
|
|
/** |
95
|
|
|
* Signed 16-bit integers little-endian |
96
|
|
|
* @type {!Object} |
97
|
|
|
* @export |
98
|
|
|
*/ |
99
|
|
|
int16 : {'bits': 16, 'signed': true}, |
100
|
|
|
/** |
101
|
|
|
* Unsigned 16-bit integers little-endian |
102
|
|
|
* @type {!Object} |
103
|
|
|
* @export |
104
|
|
|
*/ |
105
|
|
|
uInt16: {'bits': 16}, |
106
|
|
|
/** |
107
|
|
|
* Half-precision floating-point numbers little-endian |
108
|
|
|
* @type {!Object} |
109
|
|
|
* @export |
110
|
|
|
*/ |
111
|
|
|
float16: {'bits': 16, 'float': true}, |
112
|
|
|
/** |
113
|
|
|
* Signed 24-bit integers little-endian |
114
|
|
|
* @type {!Object} |
115
|
|
|
* @export |
116
|
|
|
*/ |
117
|
|
|
int24: {'bits': 24, 'signed': true}, |
118
|
|
|
/** |
119
|
|
|
* Unsigned 24-bit integers little-endian |
120
|
|
|
* @type {!Object} |
121
|
|
|
* @export |
122
|
|
|
*/ |
123
|
|
|
uInt24: {'bits': 24}, |
124
|
|
|
/** |
125
|
|
|
* Signed 32-bit integers little-endian |
126
|
|
|
* @type {!Object} |
127
|
|
|
* @export |
128
|
|
|
*/ |
129
|
|
|
int32: {'bits': 32, 'signed': true}, |
130
|
|
|
/** |
131
|
|
|
* Unsigned 32-bit integers little-endian |
132
|
|
|
* @type {!Object} |
133
|
|
|
* @export |
134
|
|
|
*/ |
135
|
|
|
uInt32: {'bits': 32}, |
136
|
|
|
/** |
137
|
|
|
* Single-precision floating-point numbers little-endian |
138
|
|
|
* @type {!Object} |
139
|
|
|
* @export |
140
|
|
|
*/ |
141
|
|
|
float32: {'bits': 32, 'float': true}, |
142
|
|
|
/** |
143
|
|
|
* Signed 40-bit integers little-endian |
144
|
|
|
* @type {!Object} |
145
|
|
|
* @export |
146
|
|
|
*/ |
147
|
|
|
int40: {'bits': 40, 'signed': true}, |
148
|
|
|
/** |
149
|
|
|
* Unsigned 40-bit integers little-endian |
150
|
|
|
* @type {!Object} |
151
|
|
|
* @export |
152
|
|
|
*/ |
153
|
|
|
uInt40: {'bits': 40}, |
154
|
|
|
/** |
155
|
|
|
* Signed 48-bit integers little-endian |
156
|
|
|
* @type {!Object} |
157
|
|
|
* @export |
158
|
|
|
*/ |
159
|
|
|
int48: {'bits': 48, 'signed': true}, |
160
|
|
|
/** |
161
|
|
|
* Unsigned 48-bit integers little-endian |
162
|
|
|
* @type {!Object} |
163
|
|
|
* @export |
164
|
|
|
*/ |
165
|
|
|
uInt48: {'bits': 48}, |
166
|
|
|
/** |
167
|
|
|
* Double-precision floating-point numbers little-endian |
168
|
|
|
* @type {!Object} |
169
|
|
|
* @export |
170
|
|
|
*/ |
171
|
|
|
float64: {'bits': 64, 'float': true}, |
172
|
|
|
// BE |
173
|
|
|
/** |
174
|
|
|
* Signed 16-bit integers big-endian |
175
|
|
|
* @type {!Object} |
176
|
|
|
* @export |
177
|
|
|
*/ |
178
|
|
|
int16BE : {'bits': 16, 'signed': true, 'be': true}, |
179
|
|
|
/** |
180
|
|
|
* Unsigned 16-bit integers big-endian |
181
|
|
|
* @type {!Object} |
182
|
|
|
* @export |
183
|
|
|
*/ |
184
|
|
|
uInt16BE: {'bits': 16, 'be': true}, |
185
|
|
|
/** |
186
|
|
|
* Half-precision floating-point numbers big-endian |
187
|
|
|
* @type {!Object} |
188
|
|
|
* @export |
189
|
|
|
*/ |
190
|
|
|
float16BE: {'bits': 16, 'float': true, 'be': true}, |
191
|
|
|
/** |
192
|
|
|
* Signed 24-bit integers big-endian |
193
|
|
|
* @type {!Object} |
194
|
|
|
* @export |
195
|
|
|
*/ |
196
|
|
|
int24BE: {'bits': 24, 'signed': true, 'be': true}, |
197
|
|
|
/** |
198
|
|
|
* Unsigned 24-bit integers big-endian |
199
|
|
|
* @type {!Object} |
200
|
|
|
* @export |
201
|
|
|
*/ |
202
|
|
|
uInt24BE: {'bits': 24, 'be': true}, |
203
|
|
|
/** |
204
|
|
|
* Signed 32-bit integers big-endian |
205
|
|
|
* @type {!Object} |
206
|
|
|
* @export |
207
|
|
|
*/ |
208
|
|
|
int32BE: {'bits': 32, 'signed': true, 'be': true}, |
209
|
|
|
/** |
210
|
|
|
* Unsigned 32-bit integers big-endian |
211
|
|
|
* @type {!Object} |
212
|
|
|
* @export |
213
|
|
|
*/ |
214
|
|
|
uInt32BE: {'bits': 32, 'be': true}, |
215
|
|
|
/** |
216
|
|
|
* Single-precision floating-point numbers big-endian |
217
|
|
|
* @type {!Object} |
218
|
|
|
* @export |
219
|
|
|
*/ |
220
|
|
|
float32BE: {'bits': 32, 'float': true, 'be': true}, |
221
|
|
|
/** |
222
|
|
|
* Signed 40-bit integers big-endian |
223
|
|
|
* @type {!Object} |
224
|
|
|
* @export |
225
|
|
|
*/ |
226
|
|
|
int40BE: {'bits': 40, 'signed': true, 'be': true}, |
227
|
|
|
/** |
228
|
|
|
* Unsigned 40-bit integers big-endian |
229
|
|
|
* @type {!Object} |
230
|
|
|
* @export |
231
|
|
|
*/ |
232
|
|
|
uInt40BE: {'bits': 40, 'be': true}, |
233
|
|
|
/** |
234
|
|
|
* Signed 48-bit integers big-endian |
235
|
|
|
* @type {!Object} |
236
|
|
|
* @export |
237
|
|
|
*/ |
238
|
|
|
int48BE: {'bits': 48, 'signed': true, 'be': true}, |
239
|
|
|
/** |
240
|
|
|
* Unsigned 48-bit integers big-endian |
241
|
|
|
* @type {!Object} |
242
|
|
|
* @export |
243
|
|
|
*/ |
244
|
|
|
uInt48BE: {'bits': 48, 'be': true}, |
245
|
|
|
/** |
246
|
|
|
* Double-precision floating-point numbers big-endian |
247
|
|
|
* @type {!Object} |
248
|
|
|
* @export |
249
|
|
|
*/ |
250
|
|
|
float64BE: {'bits': 64, 'float': true, 'be': true}, |
251
|
|
|
}; |
252
|
|
|
|