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