hap-nodejs 0.12.3-beta.2 → 0.12.3-beta.21
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/README.md +1 -0
- package/dist/accessories/AirConditioner_accessory.js +24 -24
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +23 -23
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +292 -373
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +15 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +31 -21
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +45 -48
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +11 -11
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +8 -8
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +10 -10
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +11 -11
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +19 -19
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +17 -17
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +6 -6
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +36 -47
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.js +2 -2
- package/dist/accessories/types.js.map +1 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -28
- package/dist/index.js.map +1 -1
- package/dist/lib/Accessory.d.ts +1 -58
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +747 -1149
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +1 -2
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +392 -524
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.js +6 -10
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +2 -133
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +1467 -669
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +0 -10
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +216 -280
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +1 -51
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +474 -322
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.js +112 -104
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +0 -65
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +255 -278
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +318 -381
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +0 -1
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +1 -2
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +19 -3
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +217 -218
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +0 -4
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +189 -256
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/DoorbellController.js +38 -39
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +0 -14
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +340 -415
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.js +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +56 -57
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +259 -304
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +0 -5
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +252 -269
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.js +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -106
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +2000 -2995
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -32
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +820 -1147
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +383 -679
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +29 -29
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.js +1 -1
- package/dist/lib/model/AccessoryInfo.js +101 -136
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.js +86 -89
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.js +15 -16
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.js +49 -49
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +40 -44
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -1
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +7 -11
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.js +5 -27
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.js +8 -12
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +301 -409
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.js +31 -32
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.js +9 -12
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +32 -53
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -8
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.js +8 -13
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.js +2 -3
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.js +5 -5
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +0 -27
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +71 -113
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +0 -9
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +15 -33
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +0 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +10 -10
- package/dist/BridgedCore.d.ts +0 -2
- package/dist/BridgedCore.d.ts.map +0 -1
- package/dist/BridgedCore.js +0 -43
- package/dist/BridgedCore.js.map +0 -1
- package/dist/Core.d.ts +0 -2
- package/dist/Core.d.ts.map +0 -1
- package/dist/Core.js +0 -52
- package/dist/Core.js.map +0 -1
- package/dist/lib/AccessoryLoader.d.ts +0 -28
- package/dist/lib/AccessoryLoader.d.ts.map +0 -1
- package/dist/lib/AccessoryLoader.js +0 -166
- package/dist/lib/AccessoryLoader.js.map +0 -1
- package/dist/lib/camera/Camera.d.ts +0 -43
- package/dist/lib/camera/Camera.d.ts.map +0 -1
- package/dist/lib/camera/Camera.js +0 -36
- package/dist/lib/camera/Camera.js.map +0 -1
|
@@ -1,121 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataStreamWriter = exports.DataStreamReader = exports.DataStreamParser = exports.DataFormatTags = exports.UUID = exports.SecondsSince2001 = exports.Float64 = exports.Float32 = exports.Int64 = exports.Int32 = exports.Int16 = exports.Int8 = exports.ValueWrapper = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const uuid = tslib_1.__importStar(require("../util/uuid"));
|
|
6
|
+
const hapCrypto = tslib_1.__importStar(require("../util/hapCrypto"));
|
|
7
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
9
9
|
// welcome to hell :)
|
|
10
10
|
// in this file lies madness and frustration. and It's not only about HDS. Also, JavaScript is hell
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Magics.TERMINATOR = { type: "terminator" };
|
|
16
|
-
return Magics;
|
|
17
|
-
}());
|
|
11
|
+
const debug = (0, debug_1.default)("HAP-NodeJS:DataStream:Parser");
|
|
12
|
+
class Magics {
|
|
13
|
+
static TERMINATOR = { type: "terminator" };
|
|
14
|
+
}
|
|
18
15
|
/**
|
|
19
16
|
* @group HomeKit Data Streams (HDS)
|
|
20
17
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
class ValueWrapper {
|
|
19
|
+
value;
|
|
20
|
+
constructor(value) {
|
|
23
21
|
this.value = value;
|
|
24
22
|
}
|
|
25
|
-
|
|
23
|
+
equals(obj) {
|
|
26
24
|
return this.constructor.name === obj.constructor.name && obj.value === this.value;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
30
27
|
exports.ValueWrapper = ValueWrapper;
|
|
31
28
|
/**
|
|
32
29
|
* @group HomeKit Data Streams (HDS)
|
|
33
30
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function Int8() {
|
|
37
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
38
|
-
}
|
|
39
|
-
return Int8;
|
|
40
|
-
}(ValueWrapper));
|
|
31
|
+
class Int8 extends ValueWrapper {
|
|
32
|
+
}
|
|
41
33
|
exports.Int8 = Int8;
|
|
42
34
|
/**
|
|
43
35
|
* @group HomeKit Data Streams (HDS)
|
|
44
36
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function Int16() {
|
|
48
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
49
|
-
}
|
|
50
|
-
return Int16;
|
|
51
|
-
}(ValueWrapper));
|
|
37
|
+
class Int16 extends ValueWrapper {
|
|
38
|
+
}
|
|
52
39
|
exports.Int16 = Int16;
|
|
53
40
|
/**
|
|
54
41
|
* @group HomeKit Data Streams (HDS)
|
|
55
42
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function Int32() {
|
|
59
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
60
|
-
}
|
|
61
|
-
return Int32;
|
|
62
|
-
}(ValueWrapper));
|
|
43
|
+
class Int32 extends ValueWrapper {
|
|
44
|
+
}
|
|
63
45
|
exports.Int32 = Int32;
|
|
64
46
|
/**
|
|
65
47
|
* @group HomeKit Data Streams (HDS)
|
|
66
48
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
function Int64() {
|
|
70
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
71
|
-
}
|
|
72
|
-
return Int64;
|
|
73
|
-
}(ValueWrapper));
|
|
49
|
+
class Int64 extends ValueWrapper {
|
|
50
|
+
}
|
|
74
51
|
exports.Int64 = Int64;
|
|
75
52
|
/**
|
|
76
53
|
* @group HomeKit Data Streams (HDS)
|
|
77
54
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
function Float32() {
|
|
81
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
82
|
-
}
|
|
83
|
-
return Float32;
|
|
84
|
-
}(ValueWrapper));
|
|
55
|
+
class Float32 extends ValueWrapper {
|
|
56
|
+
}
|
|
85
57
|
exports.Float32 = Float32;
|
|
86
58
|
/**
|
|
87
59
|
* @group HomeKit Data Streams (HDS)
|
|
88
60
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
function Float64() {
|
|
92
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
93
|
-
}
|
|
94
|
-
return Float64;
|
|
95
|
-
}(ValueWrapper));
|
|
61
|
+
class Float64 extends ValueWrapper {
|
|
62
|
+
}
|
|
96
63
|
exports.Float64 = Float64;
|
|
97
64
|
/**
|
|
98
65
|
* @group HomeKit Data Streams (HDS)
|
|
99
66
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
function SecondsSince2001() {
|
|
103
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
104
|
-
}
|
|
105
|
-
return SecondsSince2001;
|
|
106
|
-
}(ValueWrapper));
|
|
67
|
+
class SecondsSince2001 extends ValueWrapper {
|
|
68
|
+
}
|
|
107
69
|
exports.SecondsSince2001 = SecondsSince2001;
|
|
108
70
|
/**
|
|
109
71
|
* @group HomeKit Data Streams (HDS)
|
|
110
72
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
function UUID(value) {
|
|
73
|
+
class UUID extends ValueWrapper {
|
|
74
|
+
constructor(value) {
|
|
114
75
|
(0, assert_1.default)(uuid.isValid(value), "invalid uuid format");
|
|
115
|
-
|
|
76
|
+
super(value);
|
|
116
77
|
}
|
|
117
|
-
|
|
118
|
-
}(ValueWrapper));
|
|
78
|
+
}
|
|
119
79
|
exports.UUID = UUID;
|
|
120
80
|
/**
|
|
121
81
|
* @group HomeKit Data Streams (HDS)
|
|
@@ -164,12 +124,10 @@ var DataFormatTags;
|
|
|
164
124
|
/**
|
|
165
125
|
* @group HomeKit Data Streams (HDS)
|
|
166
126
|
*/
|
|
167
|
-
|
|
168
|
-
function DataStreamParser() {
|
|
169
|
-
}
|
|
127
|
+
class DataStreamParser {
|
|
170
128
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
171
|
-
|
|
172
|
-
|
|
129
|
+
static decode(buffer) {
|
|
130
|
+
const tag = buffer.readTag();
|
|
173
131
|
if (tag === 0 /* DataFormatTags.INVALID */) {
|
|
174
132
|
throw new Error("HDSDecoder: zero tag detected on index " + buffer.readerIndex);
|
|
175
133
|
}
|
|
@@ -216,7 +174,7 @@ var DataStreamParser = /** @class */ (function () {
|
|
|
216
174
|
return buffer.readFloat64LE();
|
|
217
175
|
}
|
|
218
176
|
else if (tag >= 64 /* DataFormatTags.UTF8_LENGTH_START */ && tag <= 96 /* DataFormatTags.UTF8_LENGTH_STOP */) {
|
|
219
|
-
|
|
177
|
+
const length = tag - 64 /* DataFormatTags.UTF8_LENGTH_START */;
|
|
220
178
|
return buffer.readUTF8(length);
|
|
221
179
|
}
|
|
222
180
|
else if (tag === 97 /* DataFormatTags.UTF8_LENGTH8 */) {
|
|
@@ -235,7 +193,7 @@ var DataStreamParser = /** @class */ (function () {
|
|
|
235
193
|
return buffer.readUTF8_NULL_terminated();
|
|
236
194
|
}
|
|
237
195
|
else if (tag >= 112 /* DataFormatTags.DATA_LENGTH_START */ && tag <= 144 /* DataFormatTags.DATA_LENGTH_STOP */) {
|
|
238
|
-
|
|
196
|
+
const length = tag - 112 /* DataFormatTags.DATA_LENGTH_START */;
|
|
239
197
|
buffer.readData(length);
|
|
240
198
|
}
|
|
241
199
|
else if (tag === 145 /* DataFormatTags.DATA_LENGTH8 */) {
|
|
@@ -254,39 +212,39 @@ var DataStreamParser = /** @class */ (function () {
|
|
|
254
212
|
return buffer.readData_terminated();
|
|
255
213
|
}
|
|
256
214
|
else if (tag >= 160 /* DataFormatTags.COMPRESSION_START */ && tag <= 207 /* DataFormatTags.COMPRESSION_STOP */) {
|
|
257
|
-
|
|
215
|
+
const index = tag - 160 /* DataFormatTags.COMPRESSION_START */;
|
|
258
216
|
return buffer.decompressData(index);
|
|
259
217
|
}
|
|
260
218
|
else if (tag >= 208 /* DataFormatTags.ARRAY_LENGTH_START */ && tag <= 222 /* DataFormatTags.ARRAY_LENGTH_STOP */) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
for (
|
|
219
|
+
const length = tag - 208 /* DataFormatTags.ARRAY_LENGTH_START */;
|
|
220
|
+
const array = [];
|
|
221
|
+
for (let i = 0; i < length; i++) {
|
|
264
222
|
array.push(this.decode(buffer));
|
|
265
223
|
}
|
|
266
224
|
return array;
|
|
267
225
|
}
|
|
268
226
|
else if (tag === 223 /* DataFormatTags.ARRAY_TERMINATED */) {
|
|
269
|
-
|
|
270
|
-
|
|
227
|
+
const array = [];
|
|
228
|
+
let element;
|
|
271
229
|
while ((element = this.decode(buffer)) !== Magics.TERMINATOR) {
|
|
272
230
|
array.push(element);
|
|
273
231
|
}
|
|
274
232
|
return array;
|
|
275
233
|
}
|
|
276
234
|
else if (tag >= 224 /* DataFormatTags.DICTIONARY_LENGTH_START */ && tag <= 238 /* DataFormatTags.DICTIONARY_LENGTH_STOP */) {
|
|
277
|
-
|
|
235
|
+
const length = tag - 224 /* DataFormatTags.DICTIONARY_LENGTH_START */;
|
|
278
236
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
279
|
-
|
|
280
|
-
for (
|
|
281
|
-
|
|
237
|
+
const dictionary = {};
|
|
238
|
+
for (let i = 0; i < length; i++) {
|
|
239
|
+
const key = this.decode(buffer);
|
|
282
240
|
dictionary[key] = this.decode(buffer);
|
|
283
241
|
}
|
|
284
242
|
return dictionary;
|
|
285
243
|
}
|
|
286
244
|
else if (tag === 239 /* DataFormatTags.DICTIONARY_TERMINATED */) {
|
|
287
245
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
288
|
-
|
|
289
|
-
|
|
246
|
+
const dictionary = {};
|
|
247
|
+
let key;
|
|
290
248
|
while ((key = this.decode(buffer)) !== Magics.TERMINATOR) {
|
|
291
249
|
dictionary[key] = this.decode(buffer); // decode value
|
|
292
250
|
}
|
|
@@ -295,10 +253,9 @@ var DataStreamParser = /** @class */ (function () {
|
|
|
295
253
|
else {
|
|
296
254
|
throw new Error("HDSDecoder: encountered unknown tag on index " + buffer.readerIndex + ": " + tag.toString(16));
|
|
297
255
|
}
|
|
298
|
-
}
|
|
256
|
+
}
|
|
299
257
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any
|
|
300
|
-
|
|
301
|
-
var _this = this;
|
|
258
|
+
static encode(data, buffer) {
|
|
302
259
|
if (data === undefined) {
|
|
303
260
|
throw new Error("HDSEncoder: cannot encode undefined");
|
|
304
261
|
}
|
|
@@ -328,15 +285,15 @@ var DataStreamParser = /** @class */ (function () {
|
|
|
328
285
|
break;
|
|
329
286
|
case "object":
|
|
330
287
|
if (Array.isArray(data)) {
|
|
331
|
-
|
|
288
|
+
const length = data.length;
|
|
332
289
|
if (length <= 12) {
|
|
333
290
|
buffer.writeTag(208 /* DataFormatTags.ARRAY_LENGTH_START */ + length);
|
|
334
291
|
}
|
|
335
292
|
else {
|
|
336
293
|
buffer.writeTag(223 /* DataFormatTags.ARRAY_TERMINATED */);
|
|
337
294
|
}
|
|
338
|
-
data.forEach(
|
|
339
|
-
|
|
295
|
+
data.forEach(element => {
|
|
296
|
+
this.encode(element, buffer);
|
|
340
297
|
});
|
|
341
298
|
if (length > 12) {
|
|
342
299
|
buffer.writeTag(3 /* DataFormatTags.TERMINATOR */);
|
|
@@ -375,17 +332,17 @@ var DataStreamParser = /** @class */ (function () {
|
|
|
375
332
|
buffer.writeData(data);
|
|
376
333
|
}
|
|
377
334
|
else { // object is treated as dictionary
|
|
378
|
-
|
|
379
|
-
.filter(
|
|
335
|
+
const entries = Object.entries(data)
|
|
336
|
+
.filter(entry => entry[1] !== undefined); // explicitly setting undefined will result in an entry here
|
|
380
337
|
if (entries.length <= 14) {
|
|
381
338
|
buffer.writeTag(224 /* DataFormatTags.DICTIONARY_LENGTH_START */ + entries.length);
|
|
382
339
|
}
|
|
383
340
|
else {
|
|
384
341
|
buffer.writeTag(239 /* DataFormatTags.DICTIONARY_TERMINATED */);
|
|
385
342
|
}
|
|
386
|
-
entries.forEach(
|
|
387
|
-
|
|
388
|
-
|
|
343
|
+
entries.forEach(entry => {
|
|
344
|
+
this.encode(entry[0], buffer); // encode key
|
|
345
|
+
this.encode(entry[1], buffer); // encode value
|
|
389
346
|
});
|
|
390
347
|
if (entries.length > 14) {
|
|
391
348
|
buffer.writeTag(3 /* DataFormatTags.TERMINATOR */);
|
|
@@ -395,145 +352,146 @@ var DataStreamParser = /** @class */ (function () {
|
|
|
395
352
|
default:
|
|
396
353
|
throw new Error("HDSEncoder: no idea how to encode value of type '" + (typeof data) + "': " + data);
|
|
397
354
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
}());
|
|
355
|
+
}
|
|
356
|
+
}
|
|
401
357
|
exports.DataStreamParser = DataStreamParser;
|
|
402
358
|
/**
|
|
403
359
|
* @group HomeKit Data Streams (HDS)
|
|
404
360
|
*/
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
361
|
+
class DataStreamReader {
|
|
362
|
+
data;
|
|
363
|
+
readerIndex;
|
|
364
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
|
+
trackedCompressedData = [];
|
|
366
|
+
constructor(data) {
|
|
409
367
|
this.data = data;
|
|
410
368
|
this.readerIndex = 0;
|
|
411
369
|
}
|
|
412
|
-
|
|
370
|
+
finished() {
|
|
413
371
|
if (this.readerIndex < this.data.length) {
|
|
414
|
-
|
|
372
|
+
const remainingHex = this.data.slice(this.readerIndex, this.data.length).toString("hex");
|
|
415
373
|
debug("WARNING Finished reading HDS stream, but there are still %d bytes remaining () %s", this.data.length - this.readerIndex, remainingHex);
|
|
416
374
|
}
|
|
417
|
-
}
|
|
375
|
+
}
|
|
418
376
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
419
|
-
|
|
377
|
+
decompressData(index) {
|
|
420
378
|
if (index >= this.trackedCompressedData.length) {
|
|
421
379
|
throw new Error("HDSDecoder: Tried decompression of data for an index out of range (index " + index +
|
|
422
380
|
" and got " + this.trackedCompressedData.length + " elements)");
|
|
423
381
|
}
|
|
424
382
|
return this.trackedCompressedData[index];
|
|
425
|
-
}
|
|
426
|
-
|
|
383
|
+
}
|
|
384
|
+
trackData(data) {
|
|
427
385
|
this.trackedCompressedData.push(data);
|
|
428
386
|
return data;
|
|
429
|
-
}
|
|
430
|
-
|
|
387
|
+
}
|
|
388
|
+
ensureLength(bytes) {
|
|
431
389
|
if (this.readerIndex + bytes > this.data.length) {
|
|
432
|
-
|
|
390
|
+
const remaining = this.data.length - this.readerIndex;
|
|
433
391
|
throw new Error("HDSDecoder: End of data stream. Tried reading " + bytes + " bytes however got only " + remaining + " remaining!");
|
|
434
392
|
}
|
|
435
|
-
}
|
|
436
|
-
|
|
393
|
+
}
|
|
394
|
+
readTag() {
|
|
437
395
|
this.ensureLength(1);
|
|
438
396
|
return this.data.readUInt8(this.readerIndex++);
|
|
439
|
-
}
|
|
440
|
-
|
|
397
|
+
}
|
|
398
|
+
readTrue() {
|
|
441
399
|
return this.trackData(true); // do those tag encoded values get cached?
|
|
442
|
-
}
|
|
443
|
-
|
|
400
|
+
}
|
|
401
|
+
readFalse() {
|
|
444
402
|
return this.trackData(false);
|
|
445
|
-
}
|
|
446
|
-
|
|
403
|
+
}
|
|
404
|
+
readNegOne() {
|
|
447
405
|
return this.trackData(-1);
|
|
448
|
-
}
|
|
449
|
-
|
|
406
|
+
}
|
|
407
|
+
readIntRange(tag) {
|
|
450
408
|
return this.trackData(tag - 8 /* DataFormatTags.INTEGER_RANGE_START_0 */); // integer values from 0-39
|
|
451
|
-
}
|
|
452
|
-
|
|
409
|
+
}
|
|
410
|
+
readInt8() {
|
|
453
411
|
this.ensureLength(1);
|
|
454
412
|
return this.trackData(this.data.readInt8(this.readerIndex++));
|
|
455
|
-
}
|
|
456
|
-
|
|
413
|
+
}
|
|
414
|
+
readInt16LE() {
|
|
457
415
|
this.ensureLength(2);
|
|
458
|
-
|
|
416
|
+
const value = this.data.readInt16LE(this.readerIndex);
|
|
459
417
|
this.readerIndex += 2;
|
|
460
418
|
return this.trackData(value);
|
|
461
|
-
}
|
|
462
|
-
|
|
419
|
+
}
|
|
420
|
+
readInt32LE() {
|
|
463
421
|
this.ensureLength(4);
|
|
464
|
-
|
|
422
|
+
const value = this.data.readInt32LE(this.readerIndex);
|
|
465
423
|
this.readerIndex += 4;
|
|
466
424
|
return this.trackData(value);
|
|
467
|
-
}
|
|
468
|
-
|
|
425
|
+
}
|
|
426
|
+
readInt64LE() {
|
|
469
427
|
this.ensureLength(8);
|
|
470
|
-
|
|
471
|
-
|
|
428
|
+
const low = this.data.readInt32LE(this.readerIndex);
|
|
429
|
+
let value = this.data.readInt32LE(this.readerIndex + 4) * 0x100000000 + low;
|
|
472
430
|
if (low < 0) {
|
|
473
431
|
value += 0x100000000;
|
|
474
432
|
}
|
|
475
433
|
this.readerIndex += 8;
|
|
476
434
|
return this.trackData(value);
|
|
477
|
-
}
|
|
478
|
-
|
|
435
|
+
}
|
|
436
|
+
readFloat32LE() {
|
|
479
437
|
this.ensureLength(4);
|
|
480
|
-
|
|
438
|
+
const value = this.data.readFloatLE(this.readerIndex);
|
|
481
439
|
this.readerIndex += 4;
|
|
482
440
|
return this.trackData(value);
|
|
483
|
-
}
|
|
484
|
-
|
|
441
|
+
}
|
|
442
|
+
readFloat64LE() {
|
|
485
443
|
this.ensureLength(8);
|
|
486
|
-
|
|
444
|
+
const value = this.data.readDoubleLE(this.readerIndex);
|
|
487
445
|
return this.trackData(value);
|
|
488
|
-
}
|
|
489
|
-
|
|
446
|
+
}
|
|
447
|
+
readLength8() {
|
|
490
448
|
this.ensureLength(1);
|
|
491
449
|
return this.data.readUInt8(this.readerIndex++);
|
|
492
|
-
}
|
|
493
|
-
|
|
450
|
+
}
|
|
451
|
+
readLength16LE() {
|
|
494
452
|
this.ensureLength(2);
|
|
495
|
-
|
|
453
|
+
const value = this.data.readUInt16LE(this.readerIndex);
|
|
496
454
|
this.readerIndex += 2;
|
|
497
455
|
return value;
|
|
498
|
-
}
|
|
499
|
-
|
|
456
|
+
}
|
|
457
|
+
readLength32LE() {
|
|
500
458
|
this.ensureLength(4);
|
|
501
|
-
|
|
459
|
+
const value = this.data.readUInt32LE(this.readerIndex);
|
|
502
460
|
this.readerIndex += 4;
|
|
503
461
|
return value;
|
|
504
|
-
}
|
|
505
|
-
|
|
462
|
+
}
|
|
463
|
+
readLength64LE() {
|
|
506
464
|
this.ensureLength(8);
|
|
507
|
-
|
|
508
|
-
|
|
465
|
+
const low = this.data.readUInt32LE(this.readerIndex);
|
|
466
|
+
const value = this.data.readUInt32LE(this.readerIndex + 4) * 0x100000000 + low;
|
|
509
467
|
this.readerIndex += 8;
|
|
510
468
|
return value;
|
|
511
|
-
}
|
|
512
|
-
|
|
469
|
+
}
|
|
470
|
+
readUTF8(length) {
|
|
513
471
|
this.ensureLength(length);
|
|
514
|
-
|
|
472
|
+
const value = this.data.toString("utf8", this.readerIndex, this.readerIndex + length);
|
|
515
473
|
this.readerIndex += length;
|
|
516
474
|
return this.trackData(value);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
|
|
475
|
+
}
|
|
476
|
+
readUTF8_Length8() {
|
|
477
|
+
const length = this.readLength8();
|
|
520
478
|
return this.readUTF8(length);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
479
|
+
}
|
|
480
|
+
readUTF8_Length16LE() {
|
|
481
|
+
const length = this.readLength16LE();
|
|
524
482
|
return this.readUTF8(length);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
483
|
+
}
|
|
484
|
+
readUTF8_Length32LE() {
|
|
485
|
+
const length = this.readLength32LE();
|
|
528
486
|
return this.readUTF8(length);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
487
|
+
}
|
|
488
|
+
readUTF8_Length64LE() {
|
|
489
|
+
const length = this.readLength64LE();
|
|
532
490
|
return this.readUTF8(length);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
491
|
+
}
|
|
492
|
+
readUTF8_NULL_terminated() {
|
|
493
|
+
let offset = this.readerIndex;
|
|
494
|
+
let nextByte;
|
|
537
495
|
for (;;) {
|
|
538
496
|
nextByte = this.data[offset];
|
|
539
497
|
if (nextByte === undefined) {
|
|
@@ -546,35 +504,35 @@ var DataStreamReader = /** @class */ (function () {
|
|
|
546
504
|
offset++;
|
|
547
505
|
}
|
|
548
506
|
}
|
|
549
|
-
|
|
507
|
+
const value = this.data.toString("utf8", this.readerIndex, offset);
|
|
550
508
|
this.readerIndex = offset + 1;
|
|
551
509
|
return this.trackData(value);
|
|
552
|
-
}
|
|
553
|
-
|
|
510
|
+
}
|
|
511
|
+
readData(length) {
|
|
554
512
|
this.ensureLength(length);
|
|
555
|
-
|
|
513
|
+
const value = this.data.slice(this.readerIndex, this.readerIndex + length);
|
|
556
514
|
this.readerIndex += length;
|
|
557
515
|
return this.trackData(value);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
516
|
+
}
|
|
517
|
+
readData_Length8() {
|
|
518
|
+
const length = this.readLength8();
|
|
561
519
|
return this.readData(length);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
520
|
+
}
|
|
521
|
+
readData_Length16LE() {
|
|
522
|
+
const length = this.readLength16LE();
|
|
565
523
|
return this.readData(length);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
|
|
524
|
+
}
|
|
525
|
+
readData_Length32LE() {
|
|
526
|
+
const length = this.readLength32LE();
|
|
569
527
|
return this.readData(length);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
528
|
+
}
|
|
529
|
+
readData_Length64LE() {
|
|
530
|
+
const length = this.readLength64LE();
|
|
573
531
|
return this.readData(length);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
532
|
+
}
|
|
533
|
+
readData_terminated() {
|
|
534
|
+
let offset = this.readerIndex;
|
|
535
|
+
let nextByte;
|
|
578
536
|
for (;;) {
|
|
579
537
|
nextByte = this.data[offset];
|
|
580
538
|
if (nextByte === undefined) {
|
|
@@ -587,34 +545,31 @@ var DataStreamReader = /** @class */ (function () {
|
|
|
587
545
|
offset++;
|
|
588
546
|
}
|
|
589
547
|
}
|
|
590
|
-
|
|
548
|
+
const value = this.data.slice(this.readerIndex, offset);
|
|
591
549
|
this.readerIndex = offset + 1;
|
|
592
550
|
return this.trackData(value);
|
|
593
|
-
}
|
|
594
|
-
|
|
551
|
+
}
|
|
552
|
+
readSecondsSince2001_01_01() {
|
|
595
553
|
// second since 2001-01-01 00:00:00
|
|
596
554
|
return this.readFloat64LE();
|
|
597
|
-
}
|
|
598
|
-
|
|
555
|
+
}
|
|
556
|
+
readUUID() {
|
|
599
557
|
this.ensureLength(16);
|
|
600
|
-
|
|
558
|
+
const value = uuid.unparse(this.data, this.readerIndex);
|
|
601
559
|
this.readerIndex += 16;
|
|
602
560
|
return this.trackData(value);
|
|
603
|
-
};
|
|
604
|
-
return DataStreamReader;
|
|
605
|
-
}());
|
|
606
|
-
exports.DataStreamReader = DataStreamReader;
|
|
607
|
-
var WrittenDataList = /** @class */ (function () {
|
|
608
|
-
function WrittenDataList() {
|
|
609
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
610
|
-
this.writtenData = [];
|
|
611
561
|
}
|
|
612
|
-
|
|
562
|
+
}
|
|
563
|
+
exports.DataStreamReader = DataStreamReader;
|
|
564
|
+
class WrittenDataList {
|
|
565
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
566
|
+
writtenData = [];
|
|
567
|
+
push(data) {
|
|
613
568
|
this.writtenData.push(data);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
for (
|
|
617
|
-
|
|
569
|
+
}
|
|
570
|
+
indexOf(data) {
|
|
571
|
+
for (let i = 0; i < this.writtenData.length; i++) {
|
|
572
|
+
const data0 = this.writtenData[i];
|
|
618
573
|
if (data === data0) {
|
|
619
574
|
return i;
|
|
620
575
|
}
|
|
@@ -625,35 +580,37 @@ var WrittenDataList = /** @class */ (function () {
|
|
|
625
580
|
}
|
|
626
581
|
}
|
|
627
582
|
return -1;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
}());
|
|
583
|
+
}
|
|
584
|
+
}
|
|
631
585
|
/**
|
|
632
586
|
* @group HomeKit Data Streams (HDS)
|
|
633
587
|
*/
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
588
|
+
class DataStreamWriter {
|
|
589
|
+
static chunkSize = 128; // seems to be a good default
|
|
590
|
+
data;
|
|
591
|
+
writerIndex;
|
|
592
|
+
writtenData = new WrittenDataList();
|
|
593
|
+
constructor() {
|
|
637
594
|
this.data = Buffer.alloc(DataStreamWriter.chunkSize);
|
|
638
595
|
this.writerIndex = 0;
|
|
639
596
|
}
|
|
640
|
-
|
|
597
|
+
length() {
|
|
641
598
|
return this.writerIndex; // since writerIndex points to the next FREE index it also represents the length
|
|
642
|
-
}
|
|
643
|
-
|
|
599
|
+
}
|
|
600
|
+
getData() {
|
|
644
601
|
return this.data.slice(0, this.writerIndex);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
|
|
602
|
+
}
|
|
603
|
+
ensureLength(bytes) {
|
|
604
|
+
const neededBytes = (this.writerIndex + bytes) - this.data.length;
|
|
648
605
|
if (neededBytes > 0) {
|
|
649
|
-
|
|
606
|
+
const chunks = Math.ceil(neededBytes / DataStreamWriter.chunkSize);
|
|
650
607
|
// don't know if it's best for performance to immediately concatenate the buffers. That way it's
|
|
651
608
|
// the easiest way to handle writing though.
|
|
652
609
|
this.data = Buffer.concat([this.data, Buffer.alloc(chunks * DataStreamWriter.chunkSize)]);
|
|
653
610
|
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
611
|
+
}
|
|
612
|
+
compressDataIfPossible(data) {
|
|
613
|
+
const index = this.writtenData.indexOf(data);
|
|
657
614
|
if (index < 0) {
|
|
658
615
|
// data is not present yet
|
|
659
616
|
this.writtenData.push(data);
|
|
@@ -665,18 +622,18 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
665
622
|
return true;
|
|
666
623
|
}
|
|
667
624
|
return false;
|
|
668
|
-
}
|
|
669
|
-
|
|
625
|
+
}
|
|
626
|
+
writeTag(tag) {
|
|
670
627
|
this.ensureLength(1);
|
|
671
628
|
this.data.writeUInt8(tag, this.writerIndex++);
|
|
672
|
-
}
|
|
673
|
-
|
|
629
|
+
}
|
|
630
|
+
writeTrue() {
|
|
674
631
|
this.writeTag(1 /* DataFormatTags.TRUE */);
|
|
675
|
-
}
|
|
676
|
-
|
|
632
|
+
}
|
|
633
|
+
writeFalse() {
|
|
677
634
|
this.writeTag(2 /* DataFormatTags.FALSE */);
|
|
678
|
-
}
|
|
679
|
-
|
|
635
|
+
}
|
|
636
|
+
writeNumber(number) {
|
|
680
637
|
if (number === -1) {
|
|
681
638
|
this.writeTag(7 /* DataFormatTags.INTEGER_MINUS_ONE */);
|
|
682
639
|
}
|
|
@@ -698,16 +655,16 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
698
655
|
else {
|
|
699
656
|
throw new Error("Tried writing unrepresentable number (" + number + ")");
|
|
700
657
|
}
|
|
701
|
-
}
|
|
702
|
-
|
|
658
|
+
}
|
|
659
|
+
writeInt8(int8) {
|
|
703
660
|
if (this.compressDataIfPossible(int8)) {
|
|
704
661
|
return;
|
|
705
662
|
}
|
|
706
663
|
this.ensureLength(2);
|
|
707
664
|
this.writeTag(48 /* DataFormatTags.INT8 */);
|
|
708
665
|
this.data.writeInt8(int8.value, this.writerIndex++);
|
|
709
|
-
}
|
|
710
|
-
|
|
666
|
+
}
|
|
667
|
+
writeInt16LE(int16) {
|
|
711
668
|
if (this.compressDataIfPossible(int16)) {
|
|
712
669
|
return;
|
|
713
670
|
}
|
|
@@ -715,8 +672,8 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
715
672
|
this.writeTag(49 /* DataFormatTags.INT16LE */);
|
|
716
673
|
this.data.writeInt16LE(int16.value, this.writerIndex);
|
|
717
674
|
this.writerIndex += 2;
|
|
718
|
-
}
|
|
719
|
-
|
|
675
|
+
}
|
|
676
|
+
writeInt32LE(int32) {
|
|
720
677
|
if (this.compressDataIfPossible(int32)) {
|
|
721
678
|
return;
|
|
722
679
|
}
|
|
@@ -724,8 +681,8 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
724
681
|
this.writeTag(50 /* DataFormatTags.INT32LE */);
|
|
725
682
|
this.data.writeInt32LE(int32.value, this.writerIndex);
|
|
726
683
|
this.writerIndex += 4;
|
|
727
|
-
}
|
|
728
|
-
|
|
684
|
+
}
|
|
685
|
+
writeInt64LE(int64) {
|
|
729
686
|
if (this.compressDataIfPossible(int64)) {
|
|
730
687
|
return;
|
|
731
688
|
}
|
|
@@ -734,8 +691,8 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
734
691
|
this.data.writeUInt32LE(int64.value, this.writerIndex); // TODO correctly implement int64; currently it's basically an int32
|
|
735
692
|
this.data.writeUInt32LE(0, this.writerIndex + 4);
|
|
736
693
|
this.writerIndex += 8;
|
|
737
|
-
}
|
|
738
|
-
|
|
694
|
+
}
|
|
695
|
+
writeFloat32LE(float32) {
|
|
739
696
|
if (this.compressDataIfPossible(float32)) {
|
|
740
697
|
return;
|
|
741
698
|
}
|
|
@@ -743,8 +700,8 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
743
700
|
this.writeTag(53 /* DataFormatTags.FLOAT32LE */);
|
|
744
701
|
this.data.writeFloatLE(float32.value, this.writerIndex);
|
|
745
702
|
this.writerIndex += 4;
|
|
746
|
-
}
|
|
747
|
-
|
|
703
|
+
}
|
|
704
|
+
writeFloat64LE(float64) {
|
|
748
705
|
if (this.compressDataIfPossible(float64)) {
|
|
749
706
|
return;
|
|
750
707
|
}
|
|
@@ -752,31 +709,31 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
752
709
|
this.writeTag(54 /* DataFormatTags.FLOAT64LE */);
|
|
753
710
|
this.data.writeDoubleLE(float64.value, this.writerIndex);
|
|
754
711
|
this.writerIndex += 8;
|
|
755
|
-
}
|
|
756
|
-
|
|
712
|
+
}
|
|
713
|
+
writeLength8(length) {
|
|
757
714
|
this.ensureLength(1);
|
|
758
715
|
this.data.writeUInt8(length, this.writerIndex++);
|
|
759
|
-
}
|
|
760
|
-
|
|
716
|
+
}
|
|
717
|
+
writeLength16LE(length) {
|
|
761
718
|
this.ensureLength(2);
|
|
762
719
|
this.data.writeUInt16LE(length, this.writerIndex);
|
|
763
720
|
this.writerIndex += 2;
|
|
764
|
-
}
|
|
765
|
-
|
|
721
|
+
}
|
|
722
|
+
writeLength32LE(length) {
|
|
766
723
|
this.ensureLength(4);
|
|
767
724
|
this.data.writeUInt32LE(length, this.writerIndex);
|
|
768
725
|
this.writerIndex += 4;
|
|
769
|
-
}
|
|
770
|
-
|
|
726
|
+
}
|
|
727
|
+
writeLength64LE(length) {
|
|
771
728
|
this.ensureLength(8);
|
|
772
729
|
hapCrypto.writeUInt64LE(length, this.data, this.writerIndex);
|
|
773
730
|
this.writerIndex += 8;
|
|
774
|
-
}
|
|
775
|
-
|
|
731
|
+
}
|
|
732
|
+
writeUTF8(utf8) {
|
|
776
733
|
if (this.compressDataIfPossible(utf8)) {
|
|
777
734
|
return;
|
|
778
735
|
}
|
|
779
|
-
|
|
736
|
+
const length = Buffer.byteLength(utf8);
|
|
780
737
|
if (length <= 32) {
|
|
781
738
|
this.ensureLength(1 + length);
|
|
782
739
|
this.writeTag(64 /* DataFormatTags.UTF8_LENGTH_START */ + utf8.length);
|
|
@@ -797,48 +754,48 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
797
754
|
else {
|
|
798
755
|
this.writeUTF8_NULL_terminated(utf8);
|
|
799
756
|
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
757
|
+
}
|
|
758
|
+
_writeUTF8(utf8) {
|
|
759
|
+
const byteLength = Buffer.byteLength(utf8);
|
|
803
760
|
this.ensureLength(byteLength);
|
|
804
761
|
this.data.write(utf8, this.writerIndex, byteLength, "utf8");
|
|
805
762
|
this.writerIndex += byteLength;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
|
|
763
|
+
}
|
|
764
|
+
writeUTF8_Length8(utf8) {
|
|
765
|
+
const length = Buffer.byteLength(utf8);
|
|
809
766
|
this.ensureLength(2 + length);
|
|
810
767
|
this.writeTag(97 /* DataFormatTags.UTF8_LENGTH8 */);
|
|
811
768
|
this.writeLength8(length);
|
|
812
769
|
this._writeUTF8(utf8);
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
|
|
770
|
+
}
|
|
771
|
+
writeUTF8_Length16LE(utf8) {
|
|
772
|
+
const length = Buffer.byteLength(utf8);
|
|
816
773
|
this.ensureLength(3 + length);
|
|
817
774
|
this.writeTag(98 /* DataFormatTags.UTF8_LENGTH16LE */);
|
|
818
775
|
this.writeLength16LE(length);
|
|
819
776
|
this._writeUTF8(utf8);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
|
|
777
|
+
}
|
|
778
|
+
writeUTF8_Length32LE(utf8) {
|
|
779
|
+
const length = Buffer.byteLength(utf8);
|
|
823
780
|
this.ensureLength(5 + length);
|
|
824
781
|
this.writeTag(99 /* DataFormatTags.UTF8_LENGTH32LE */);
|
|
825
782
|
this.writeLength32LE(length);
|
|
826
783
|
this._writeUTF8(utf8);
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
|
|
784
|
+
}
|
|
785
|
+
writeUTF8_Length64LE(utf8) {
|
|
786
|
+
const length = Buffer.byteLength(utf8);
|
|
830
787
|
this.ensureLength(9 + length);
|
|
831
788
|
this.writeTag(100 /* DataFormatTags.UTF8_LENGTH64LE */);
|
|
832
789
|
this.writeLength64LE(length);
|
|
833
790
|
this._writeUTF8(utf8);
|
|
834
|
-
}
|
|
835
|
-
|
|
791
|
+
}
|
|
792
|
+
writeUTF8_NULL_terminated(utf8) {
|
|
836
793
|
this.ensureLength(1 + Buffer.byteLength(utf8) + 1);
|
|
837
794
|
this.writeTag(111 /* DataFormatTags.UTF8_NULL_TERMINATED */);
|
|
838
795
|
this._writeUTF8(utf8);
|
|
839
796
|
this.data.writeUInt8(0, this.writerIndex++);
|
|
840
|
-
}
|
|
841
|
-
|
|
797
|
+
}
|
|
798
|
+
writeData(data) {
|
|
842
799
|
if (this.compressDataIfPossible(data)) {
|
|
843
800
|
return;
|
|
844
801
|
}
|
|
@@ -861,44 +818,44 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
861
818
|
else {
|
|
862
819
|
this.writeData_terminated(data);
|
|
863
820
|
}
|
|
864
|
-
}
|
|
865
|
-
|
|
821
|
+
}
|
|
822
|
+
_writeData(data) {
|
|
866
823
|
this.ensureLength(data.length);
|
|
867
|
-
for (
|
|
824
|
+
for (let i = 0; i < data.length; i++) {
|
|
868
825
|
this.data[this.writerIndex++] = data[i];
|
|
869
826
|
}
|
|
870
|
-
}
|
|
871
|
-
|
|
827
|
+
}
|
|
828
|
+
writeData_Length8(data) {
|
|
872
829
|
this.ensureLength(2 + data.length);
|
|
873
830
|
this.writeTag(145 /* DataFormatTags.DATA_LENGTH8 */);
|
|
874
831
|
this.writeLength8(data.length);
|
|
875
832
|
this._writeData(data);
|
|
876
|
-
}
|
|
877
|
-
|
|
833
|
+
}
|
|
834
|
+
writeData_Length16LE(data) {
|
|
878
835
|
this.ensureLength(3 + data.length);
|
|
879
836
|
this.writeTag(146 /* DataFormatTags.DATA_LENGTH16LE */);
|
|
880
837
|
this.writeLength16LE(data.length);
|
|
881
838
|
this._writeData(data);
|
|
882
|
-
}
|
|
883
|
-
|
|
839
|
+
}
|
|
840
|
+
writeData_Length32LE(data) {
|
|
884
841
|
this.ensureLength(5 + data.length);
|
|
885
842
|
this.writeTag(147 /* DataFormatTags.DATA_LENGTH32LE */);
|
|
886
843
|
this.writeLength32LE(data.length);
|
|
887
844
|
this._writeData(data);
|
|
888
|
-
}
|
|
889
|
-
|
|
845
|
+
}
|
|
846
|
+
writeData_Length64LE(data) {
|
|
890
847
|
this.ensureLength(9 + data.length);
|
|
891
848
|
this.writeTag(148 /* DataFormatTags.DATA_LENGTH64LE */);
|
|
892
849
|
this.writeLength64LE(data.length);
|
|
893
850
|
this._writeData(data);
|
|
894
|
-
}
|
|
895
|
-
|
|
851
|
+
}
|
|
852
|
+
writeData_terminated(data) {
|
|
896
853
|
this.ensureLength(1 + data.length + 1);
|
|
897
854
|
this.writeTag(159 /* DataFormatTags.DATA_TERMINATED */);
|
|
898
855
|
this._writeData(data);
|
|
899
856
|
this.writeTag(3 /* DataFormatTags.TERMINATOR */);
|
|
900
|
-
}
|
|
901
|
-
|
|
857
|
+
}
|
|
858
|
+
writeSecondsSince2001_01_01(seconds) {
|
|
902
859
|
if (this.compressDataIfPossible(seconds)) {
|
|
903
860
|
return;
|
|
904
861
|
}
|
|
@@ -906,8 +863,8 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
906
863
|
this.writeTag(6 /* DataFormatTags.DATE */);
|
|
907
864
|
this.data.writeDoubleLE(seconds.value, this.writerIndex);
|
|
908
865
|
this.writerIndex += 8;
|
|
909
|
-
}
|
|
910
|
-
|
|
866
|
+
}
|
|
867
|
+
writeUUID(uuid_string) {
|
|
911
868
|
(0, assert_1.default)(uuid.isValid(uuid_string), "supplied uuid is invalid");
|
|
912
869
|
if (this.compressDataIfPossible(new UUID(uuid_string))) {
|
|
913
870
|
return;
|
|
@@ -916,9 +873,7 @@ var DataStreamWriter = /** @class */ (function () {
|
|
|
916
873
|
this.writeTag(5 /* DataFormatTags.UUID */);
|
|
917
874
|
uuid.write(uuid_string, this.data, this.writerIndex);
|
|
918
875
|
this.writerIndex += 16;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
return DataStreamWriter;
|
|
922
|
-
}());
|
|
876
|
+
}
|
|
877
|
+
}
|
|
923
878
|
exports.DataStreamWriter = DataStreamWriter;
|
|
924
879
|
//# sourceMappingURL=DataStreamParser.js.map
|