@garmin/fitsdk 21.161.0 → 21.168.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +338 -338
- package/package.json +23 -23
- package/src/accumulator.js +58 -58
- package/src/bit-stream.js +85 -85
- package/src/crc-calculator.js +55 -55
- package/src/decoder.js +839 -830
- package/src/encoder.js +323 -323
- package/src/fit.js +170 -170
- package/src/index.js +20 -20
- package/src/mesg-definition.js +270 -269
- package/src/output-stream.js +220 -220
- package/src/profile.js +27999 -27254
- package/src/stream.js +258 -258
- package/src/utils-hr-mesg.js +174 -174
- package/src/utils-internal.js +53 -35
- package/src/utils-memo-glob.js +65 -0
- package/src/utils.js +66 -66
package/src/output-stream.js
CHANGED
|
@@ -1,220 +1,220 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright 2025 Garmin International, Inc.
|
|
3
|
-
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
-
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
-
// Transfer (FIT) Protocol License.
|
|
6
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
-
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
10
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import FIT from "./fit.js";
|
|
14
|
-
|
|
15
|
-
const ONE_MEGABYTE = 1048576;
|
|
16
|
-
const TEN_MEGABYTES = ONE_MEGABYTE * 10;
|
|
17
|
-
const HALF_MEGABYTE = ONE_MEGABYTE / 2;
|
|
18
|
-
|
|
19
|
-
class OutputStream {
|
|
20
|
-
#arrayBuffer = null;
|
|
21
|
-
#dataView = null;
|
|
22
|
-
#byteOffset = 0;
|
|
23
|
-
#resizeByBytes = 0;
|
|
24
|
-
#baseTypeDefinitions = null;
|
|
25
|
-
#textEncoder = new TextEncoder();
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Creates an OutputStream
|
|
29
|
-
* @constructor
|
|
30
|
-
* @param {Object=} [options] - Read options (optional)
|
|
31
|
-
* @param {Number} [options.initialByteLength=0.5MB] - (optional, default 0.5 MB)
|
|
32
|
-
* @param {Number} [options.maxByteLength=2MB] - (optional, default 2 MB)
|
|
33
|
-
* @param {Number} [options.resizeByBytes=0.5MB] - (optional, default 0.5 MB)
|
|
34
|
-
*/
|
|
35
|
-
constructor({
|
|
36
|
-
initialByteLength = HALF_MEGABYTE,
|
|
37
|
-
maxByteLength = TEN_MEGABYTES,
|
|
38
|
-
resizeByBytes = HALF_MEGABYTE,
|
|
39
|
-
} = {}) {
|
|
40
|
-
this.#arrayBuffer = new ArrayBuffer(initialByteLength, { maxByteLength, });
|
|
41
|
-
this.#dataView = new DataView(this.#arrayBuffer);
|
|
42
|
-
|
|
43
|
-
this.#resizeByBytes = resizeByBytes;
|
|
44
|
-
|
|
45
|
-
this.#baseTypeDefinitions = {
|
|
46
|
-
[FIT.BaseType.ENUM]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
47
|
-
[FIT.BaseType.UINT8]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
48
|
-
[FIT.BaseType.UINT16]: { setValue: this.#dataView.setUint16.bind(this.#dataView), size: 2, mask: 0xFFFF, },
|
|
49
|
-
[FIT.BaseType.UINT32]: { setValue: this.#dataView.setUint32.bind(this.#dataView), size: 4, mask: 0xFFFFFFFF, },
|
|
50
|
-
[FIT.BaseType.UINT64]: { setValue: this.#dataView.setBigUint64.bind(this.#dataView), size: 8, mask: 0xFFFFFFFFFFFFFFFFn, },
|
|
51
|
-
[FIT.BaseType.SINT8]: { setValue: this.#dataView.setInt8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
52
|
-
[FIT.BaseType.SINT16]: { setValue: this.#dataView.setInt16.bind(this.#dataView), size: 2, mask: 0xFFFF, },
|
|
53
|
-
[FIT.BaseType.SINT32]: { setValue: this.#dataView.setInt32.bind(this.#dataView), size: 4, mask: 0xFFFFFFFF, },
|
|
54
|
-
[FIT.BaseType.SINT64]: { setValue: this.#dataView.setBigInt64.bind(this.#dataView), size: 8, mask: 0xFFFFFFFFFFFFFFFFn, },
|
|
55
|
-
[FIT.BaseType.FLOAT32]: { setValue: this.#dataView.setFloat32.bind(this.#dataView), size: 4, },
|
|
56
|
-
[FIT.BaseType.FLOAT64]: { setValue: this.#dataView.setFloat64.bind(this.#dataView), size: 8, },
|
|
57
|
-
[FIT.BaseType.UINT8Z]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
58
|
-
[FIT.BaseType.UINT16Z]: { setValue: this.#dataView.setUint16.bind(this.#dataView), size: 2, mask: 0xFFFF, },
|
|
59
|
-
[FIT.BaseType.UINT32Z]: { setValue: this.#dataView.setUint32.bind(this.#dataView), size: 4, mask: 0xFFFFFFFF, },
|
|
60
|
-
[FIT.BaseType.UINT64Z]: { setValue: this.#dataView.setBigUint64.bind(this.#dataView), size: 8, mask: 0xFFFFFFFFFFFFFFFFn, },
|
|
61
|
-
[FIT.BaseType.BYTE]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get length() {
|
|
66
|
-
return this.#byteOffset;
|
|
67
|
-
}
|
|
68
|
-
get uint8Array() {
|
|
69
|
-
return new Uint8Array(this.#arrayBuffer.slice(0, this.#byteOffset));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
writeUInt8(value) {
|
|
73
|
-
return this.write(value, FIT.BaseType.UINT8);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
writeUInt16(value) {
|
|
77
|
-
return this.write(value, FIT.BaseType.UINT16);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
writeUInt32(value) {
|
|
81
|
-
return this.write(value, FIT.BaseType.UINT32);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
writeUInt64(value) {
|
|
85
|
-
return this.write(value, FIT.BaseType.UINT64);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
writeSInt8(value) {
|
|
89
|
-
return this.write(value, FIT.BaseType.SINT8);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
writeSInt16(value) {
|
|
93
|
-
return this.write(value, FIT.BaseType.SINT16);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
writeSInt32(value) {
|
|
97
|
-
return this.write(value, FIT.BaseType.SINT32);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
writeSInt64(value) {
|
|
101
|
-
return this.write(value, FIT.BaseType.SINT64);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
writeFloat32(value) {
|
|
105
|
-
return this.write(value, FIT.BaseType.FLOAT32);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
writeFloat64(value) {
|
|
109
|
-
return this.write(value, FIT.BaseType.FLOAT64);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
writeUInt8z(value) {
|
|
113
|
-
return this.write(value, FIT.BaseType.UINT8Z);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
writeUInt16z(value) {
|
|
117
|
-
return this.write(value, FIT.BaseType.UINT16Z);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
writeUInt32z(value) {
|
|
121
|
-
return this.write(value, FIT.BaseType.UINT32Z);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
writeUInt64z(value) {
|
|
125
|
-
return this.write(value, FIT.BaseType.UINT64Z);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
writeByte(value) {
|
|
129
|
-
return this.write(value, FIT.BaseType.BYTE);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
writeString(text) {
|
|
133
|
-
const bytes = this.#textEncoder.encode(text);
|
|
134
|
-
|
|
135
|
-
this.#resizeIfNeeded(bytes.byteLength);
|
|
136
|
-
|
|
137
|
-
const uint8Array = new Uint8Array(this.#arrayBuffer, this.#byteOffset, bytes.byteLength);
|
|
138
|
-
uint8Array.set(bytes);
|
|
139
|
-
|
|
140
|
-
this.#byteOffset += bytes.byteLength;
|
|
141
|
-
|
|
142
|
-
// Add a null terminator
|
|
143
|
-
this.writeUInt8(0);
|
|
144
|
-
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
write(value, baseType) {
|
|
149
|
-
if (baseType === FIT.BaseType.STRING) {
|
|
150
|
-
return this.writeString(value);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
this.#setValues(baseType, value);
|
|
154
|
-
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
set(typedarray, targetOffset = 0) {
|
|
159
|
-
this.#resizeIfNeeded(typedarray.byteLength + targetOffset);
|
|
160
|
-
|
|
161
|
-
const uint8Array = new Uint8Array(this.#arrayBuffer);
|
|
162
|
-
uint8Array.set(typedarray, targetOffset);
|
|
163
|
-
|
|
164
|
-
this.#byteOffset = Math.max(this.#byteOffset, typedarray.byteLength + targetOffset);
|
|
165
|
-
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
[Symbol.iterator]() {
|
|
170
|
-
let start = 0;
|
|
171
|
-
const end = this.#byteOffset;
|
|
172
|
-
const dataView = this.#dataView;
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
next() {
|
|
176
|
-
if (start < end) {
|
|
177
|
-
return { value: dataView.getUint8(start++), done: false, };
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
return { done: true, };
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
#setValues(baseType, value) {
|
|
187
|
-
const values = Array.isArray(value) ? value : [value,];
|
|
188
|
-
|
|
189
|
-
values.forEach((value) => {
|
|
190
|
-
return this.#setValue(baseType, value);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
#setValue(baseType, value) {
|
|
195
|
-
const def = this.#baseTypeDefinitions[baseType];
|
|
196
|
-
|
|
197
|
-
this.#resizeIfNeeded(def.size);
|
|
198
|
-
|
|
199
|
-
const val = def.mask == null ? value : value & def.mask;
|
|
200
|
-
|
|
201
|
-
def.setValue(this.#byteOffset, val, true);
|
|
202
|
-
this.#byteOffset += def.size;
|
|
203
|
-
|
|
204
|
-
return this;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
#resizeIfNeeded(byteCount = 1) {
|
|
208
|
-
if (this.#arrayBuffer.byteLength - this.#byteOffset >= byteCount) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (!this.#arrayBuffer.resizable) {
|
|
213
|
-
throw new Error("Can not resize OutputStream. Set a larger initial size.");
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
this.#arrayBuffer.resize(this.#arrayBuffer.byteLength + Math.max(this.#resizeByBytes, byteCount));
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export default OutputStream;
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright 2025 Garmin International, Inc.
|
|
3
|
+
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
+
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
+
// Transfer (FIT) Protocol License.
|
|
6
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
+
// Profile Version = 21.168.0Release
|
|
9
|
+
// Tag = production/release/21.168.0-0-gb831b31
|
|
10
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import FIT from "./fit.js";
|
|
14
|
+
|
|
15
|
+
const ONE_MEGABYTE = 1048576;
|
|
16
|
+
const TEN_MEGABYTES = ONE_MEGABYTE * 10;
|
|
17
|
+
const HALF_MEGABYTE = ONE_MEGABYTE / 2;
|
|
18
|
+
|
|
19
|
+
class OutputStream {
|
|
20
|
+
#arrayBuffer = null;
|
|
21
|
+
#dataView = null;
|
|
22
|
+
#byteOffset = 0;
|
|
23
|
+
#resizeByBytes = 0;
|
|
24
|
+
#baseTypeDefinitions = null;
|
|
25
|
+
#textEncoder = new TextEncoder();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates an OutputStream
|
|
29
|
+
* @constructor
|
|
30
|
+
* @param {Object=} [options] - Read options (optional)
|
|
31
|
+
* @param {Number} [options.initialByteLength=0.5MB] - (optional, default 0.5 MB)
|
|
32
|
+
* @param {Number} [options.maxByteLength=2MB] - (optional, default 2 MB)
|
|
33
|
+
* @param {Number} [options.resizeByBytes=0.5MB] - (optional, default 0.5 MB)
|
|
34
|
+
*/
|
|
35
|
+
constructor({
|
|
36
|
+
initialByteLength = HALF_MEGABYTE,
|
|
37
|
+
maxByteLength = TEN_MEGABYTES,
|
|
38
|
+
resizeByBytes = HALF_MEGABYTE,
|
|
39
|
+
} = {}) {
|
|
40
|
+
this.#arrayBuffer = new ArrayBuffer(initialByteLength, { maxByteLength, });
|
|
41
|
+
this.#dataView = new DataView(this.#arrayBuffer);
|
|
42
|
+
|
|
43
|
+
this.#resizeByBytes = resizeByBytes;
|
|
44
|
+
|
|
45
|
+
this.#baseTypeDefinitions = {
|
|
46
|
+
[FIT.BaseType.ENUM]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
47
|
+
[FIT.BaseType.UINT8]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
48
|
+
[FIT.BaseType.UINT16]: { setValue: this.#dataView.setUint16.bind(this.#dataView), size: 2, mask: 0xFFFF, },
|
|
49
|
+
[FIT.BaseType.UINT32]: { setValue: this.#dataView.setUint32.bind(this.#dataView), size: 4, mask: 0xFFFFFFFF, },
|
|
50
|
+
[FIT.BaseType.UINT64]: { setValue: this.#dataView.setBigUint64.bind(this.#dataView), size: 8, mask: 0xFFFFFFFFFFFFFFFFn, },
|
|
51
|
+
[FIT.BaseType.SINT8]: { setValue: this.#dataView.setInt8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
52
|
+
[FIT.BaseType.SINT16]: { setValue: this.#dataView.setInt16.bind(this.#dataView), size: 2, mask: 0xFFFF, },
|
|
53
|
+
[FIT.BaseType.SINT32]: { setValue: this.#dataView.setInt32.bind(this.#dataView), size: 4, mask: 0xFFFFFFFF, },
|
|
54
|
+
[FIT.BaseType.SINT64]: { setValue: this.#dataView.setBigInt64.bind(this.#dataView), size: 8, mask: 0xFFFFFFFFFFFFFFFFn, },
|
|
55
|
+
[FIT.BaseType.FLOAT32]: { setValue: this.#dataView.setFloat32.bind(this.#dataView), size: 4, },
|
|
56
|
+
[FIT.BaseType.FLOAT64]: { setValue: this.#dataView.setFloat64.bind(this.#dataView), size: 8, },
|
|
57
|
+
[FIT.BaseType.UINT8Z]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
58
|
+
[FIT.BaseType.UINT16Z]: { setValue: this.#dataView.setUint16.bind(this.#dataView), size: 2, mask: 0xFFFF, },
|
|
59
|
+
[FIT.BaseType.UINT32Z]: { setValue: this.#dataView.setUint32.bind(this.#dataView), size: 4, mask: 0xFFFFFFFF, },
|
|
60
|
+
[FIT.BaseType.UINT64Z]: { setValue: this.#dataView.setBigUint64.bind(this.#dataView), size: 8, mask: 0xFFFFFFFFFFFFFFFFn, },
|
|
61
|
+
[FIT.BaseType.BYTE]: { setValue: this.#dataView.setUint8.bind(this.#dataView), size: 1, mask: 0xFF, },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get length() {
|
|
66
|
+
return this.#byteOffset;
|
|
67
|
+
}
|
|
68
|
+
get uint8Array() {
|
|
69
|
+
return new Uint8Array(this.#arrayBuffer.slice(0, this.#byteOffset));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
writeUInt8(value) {
|
|
73
|
+
return this.write(value, FIT.BaseType.UINT8);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
writeUInt16(value) {
|
|
77
|
+
return this.write(value, FIT.BaseType.UINT16);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
writeUInt32(value) {
|
|
81
|
+
return this.write(value, FIT.BaseType.UINT32);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
writeUInt64(value) {
|
|
85
|
+
return this.write(value, FIT.BaseType.UINT64);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
writeSInt8(value) {
|
|
89
|
+
return this.write(value, FIT.BaseType.SINT8);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
writeSInt16(value) {
|
|
93
|
+
return this.write(value, FIT.BaseType.SINT16);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
writeSInt32(value) {
|
|
97
|
+
return this.write(value, FIT.BaseType.SINT32);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
writeSInt64(value) {
|
|
101
|
+
return this.write(value, FIT.BaseType.SINT64);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
writeFloat32(value) {
|
|
105
|
+
return this.write(value, FIT.BaseType.FLOAT32);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
writeFloat64(value) {
|
|
109
|
+
return this.write(value, FIT.BaseType.FLOAT64);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
writeUInt8z(value) {
|
|
113
|
+
return this.write(value, FIT.BaseType.UINT8Z);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
writeUInt16z(value) {
|
|
117
|
+
return this.write(value, FIT.BaseType.UINT16Z);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
writeUInt32z(value) {
|
|
121
|
+
return this.write(value, FIT.BaseType.UINT32Z);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
writeUInt64z(value) {
|
|
125
|
+
return this.write(value, FIT.BaseType.UINT64Z);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
writeByte(value) {
|
|
129
|
+
return this.write(value, FIT.BaseType.BYTE);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
writeString(text) {
|
|
133
|
+
const bytes = this.#textEncoder.encode(text);
|
|
134
|
+
|
|
135
|
+
this.#resizeIfNeeded(bytes.byteLength);
|
|
136
|
+
|
|
137
|
+
const uint8Array = new Uint8Array(this.#arrayBuffer, this.#byteOffset, bytes.byteLength);
|
|
138
|
+
uint8Array.set(bytes);
|
|
139
|
+
|
|
140
|
+
this.#byteOffset += bytes.byteLength;
|
|
141
|
+
|
|
142
|
+
// Add a null terminator
|
|
143
|
+
this.writeUInt8(0);
|
|
144
|
+
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
write(value, baseType) {
|
|
149
|
+
if (baseType === FIT.BaseType.STRING) {
|
|
150
|
+
return this.writeString(value);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this.#setValues(baseType, value);
|
|
154
|
+
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
set(typedarray, targetOffset = 0) {
|
|
159
|
+
this.#resizeIfNeeded(typedarray.byteLength + targetOffset);
|
|
160
|
+
|
|
161
|
+
const uint8Array = new Uint8Array(this.#arrayBuffer);
|
|
162
|
+
uint8Array.set(typedarray, targetOffset);
|
|
163
|
+
|
|
164
|
+
this.#byteOffset = Math.max(this.#byteOffset, typedarray.byteLength + targetOffset);
|
|
165
|
+
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
[Symbol.iterator]() {
|
|
170
|
+
let start = 0;
|
|
171
|
+
const end = this.#byteOffset;
|
|
172
|
+
const dataView = this.#dataView;
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
next() {
|
|
176
|
+
if (start < end) {
|
|
177
|
+
return { value: dataView.getUint8(start++), done: false, };
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return { done: true, };
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#setValues(baseType, value) {
|
|
187
|
+
const values = Array.isArray(value) ? value : [value,];
|
|
188
|
+
|
|
189
|
+
values.forEach((value) => {
|
|
190
|
+
return this.#setValue(baseType, value);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
#setValue(baseType, value) {
|
|
195
|
+
const def = this.#baseTypeDefinitions[baseType];
|
|
196
|
+
|
|
197
|
+
this.#resizeIfNeeded(def.size);
|
|
198
|
+
|
|
199
|
+
const val = def.mask == null ? value : value & def.mask;
|
|
200
|
+
|
|
201
|
+
def.setValue(this.#byteOffset, val, true);
|
|
202
|
+
this.#byteOffset += def.size;
|
|
203
|
+
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
#resizeIfNeeded(byteCount = 1) {
|
|
208
|
+
if (this.#arrayBuffer.byteLength - this.#byteOffset >= byteCount) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!this.#arrayBuffer.resizable) {
|
|
213
|
+
throw new Error("Can not resize OutputStream. Set a larger initial size.");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this.#arrayBuffer.resize(this.#arrayBuffer.byteLength + Math.max(this.#resizeByBytes, byteCount));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export default OutputStream;
|