hap-nodejs 1.0.0-beta.1 → 1.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 +4 -3
- package/@types/simple-plist.d.ts +2 -1
- package/README.md +2 -1
- package/dist/BridgedCore.js +6 -5
- package/dist/BridgedCore.js.map +1 -1
- package/dist/Core.js +12 -10
- package/dist/Core.js.map +1 -1
- package/dist/accessories/AirConditioner_accessory.js +27 -27
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +17 -16
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +433 -45
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +8 -13
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +11 -12
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +5 -6
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +34 -25
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +11 -12
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +8 -9
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +9 -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 -20
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +13 -14
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +7 -8
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +9 -10
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +8 -9
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +2 -2
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +31 -32
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/index.d.ts +54 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -9
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +65 -124
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +66 -5
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +142 -37
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +539 -451
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/AccessoryLoader.d.ts +20 -8
- package/dist/lib/AccessoryLoader.d.ts.map +1 -1
- package/dist/lib/AccessoryLoader.js +115 -93
- package/dist/lib/AccessoryLoader.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +99 -6
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +558 -21
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +3 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +2 -0
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +918 -59
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +308 -257
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +114 -21
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +231 -230
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +339 -15
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +59 -50
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/Camera.d.ts +15 -6
- package/dist/lib/camera/Camera.d.ts.map +1 -1
- package/dist/lib/camera/Camera.js +6 -3
- package/dist/lib/camera/Camera.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +24 -19
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +230 -207
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +202 -43
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +303 -189
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +326 -0
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -0
- package/dist/lib/camera/RecordingManagement.js +833 -0
- package/dist/lib/camera/RecordingManagement.js.map +1 -0
- package/dist/lib/camera/index.d.ts +4 -3
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +1 -0
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +37 -11
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +101 -86
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +290 -12
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +403 -47
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +31 -10
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js +7 -0
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +47 -1
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +65 -11
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +111 -42
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +228 -203
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +4 -4
- package/dist/lib/datastream/DataStreamManagement.d.ts +25 -19
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +42 -35
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +63 -24
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +132 -86
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +154 -50
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +242 -147
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +181 -0
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +968 -499
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +58 -0
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +173 -6
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts +1 -0
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +29 -21
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +62 -29
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/model/AccessoryInfo.d.ts +16 -10
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +87 -73
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +3 -0
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +7 -4
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +3 -0
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +4 -0
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +12 -11
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +68 -65
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +12 -1
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +13 -5
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/clone.d.ts +2 -1
- package/dist/lib/util/clone.d.ts.map +1 -1
- package/dist/lib/util/clone.js +2 -0
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +4 -1
- package/dist/lib/util/color-utils.d.ts.map +1 -1
- package/dist/lib/util/color-utils.js +5 -2
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +62 -15
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +234 -171
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +35 -7
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +86 -78
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +2 -0
- package/dist/lib/util/hapStatusError.d.ts.map +1 -1
- package/dist/lib/util/hapStatusError.js +5 -3
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.d.ts +7 -0
- package/dist/lib/util/net-utils.d.ts.map +1 -1
- package/dist/lib/util/net-utils.js +11 -4
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.d.ts +6 -1
- package/dist/lib/util/once.d.ts.map +1 -1
- package/dist/lib/util/once.js +9 -3
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +15 -0
- package/dist/lib/util/promise-utils.d.ts.map +1 -0
- package/dist/lib/util/promise-utils.js +36 -0
- package/dist/lib/util/promise-utils.js.map +1 -0
- package/dist/lib/util/request-util.d.ts +16 -0
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +43 -27
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +7 -1
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +13 -7
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +95 -5
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +96 -24
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +2 -3
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +25 -19
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +271 -18
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -1
- package/package.json +28 -25
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise-utils.js","sourceRoot":"","sources":["../../../src/lib/util/promise-utils.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO,IAAI,OAAO,CAAO,UAAA,OAAO;QAC9B,UAAU,CAAC,cAAM,OAAA,OAAO,EAAE,EAAT,CAAS,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,wCAIC;AAUD,wDAAwD;AACxD,SAAgB,cAAc,CAAuD,OAAe,EAAE,KAAY,EAAE,OAAc;IAAd,wBAAA,EAAA,cAAc;IAChI,OAAO,IAAI,OAAO,CAAW,UAAC,OAAO,EAAE,MAAM;QAC3C,wCAAwC;QACxC,IAAI,SAAyB,CAAC;QAE9B,8DAA8D;QAC9D,IAAM,eAAe,GAAG;YAAC,cAAY;iBAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;gBAAZ,yBAAY;;YACnC,YAAY,CAAC,SAAS,CAAC,CAAC;YAExB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC1E,CAAC,CAAC;QAEF,SAAS,GAAG,UAAU,CAAC;YACrB,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;YAC/C,MAAM,CAAC,IAAI,KAAK,CAAC,+BAAwB,KAAK,gBAAa,CAAC,CAAC,CAAC;QAChE,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAnBD,wCAmBC"}
|
|
@@ -9,12 +9,28 @@ import { CharacteristicProps, Formats } from "../Characteristic";
|
|
|
9
9
|
* @param value - The value which should be formatted
|
|
10
10
|
* @param props - The characteristic properties used to format the value.
|
|
11
11
|
* @private
|
|
12
|
+
* @group Utils
|
|
12
13
|
*/
|
|
13
14
|
export declare function formatOutgoingCharacteristicValue(value: Nullable<CharacteristicValue>, props: CharacteristicProps): Nullable<CharacteristicValue>;
|
|
14
15
|
export declare function formatOutgoingCharacteristicValue(value: CharacteristicValue, props: CharacteristicProps): CharacteristicValue;
|
|
16
|
+
/**
|
|
17
|
+
* @group Utils
|
|
18
|
+
*/
|
|
15
19
|
export declare function isNumericFormat(format: Formats | string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* @group Utils
|
|
22
|
+
*/
|
|
16
23
|
export declare function isUnsignedNumericFormat(format: Formats | string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @group Utils
|
|
26
|
+
*/
|
|
17
27
|
export declare function isIntegerNumericFormat(format: Formats | string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @group Utils
|
|
30
|
+
*/
|
|
18
31
|
export declare function numericLowerBound(format: Formats | string): number;
|
|
32
|
+
/**
|
|
33
|
+
* @group Utils
|
|
34
|
+
*/
|
|
19
35
|
export declare function numericUpperBound(format: Formats | string): number;
|
|
20
36
|
//# sourceMappingURL=request-util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-util.d.ts","sourceRoot":"","sources":["../../../src/lib/util/request-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjE
|
|
1
|
+
{"version":3,"file":"request-util.d.ts","sourceRoot":"","sources":["../../../src/lib/util/request-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AACnJ,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,GAAG,mBAAmB,CAAA;AAkB9H;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAYjE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAUzE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAWxE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAclE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAkBlE"}
|
|
@@ -17,74 +17,90 @@ function formatOutgoingCharacteristicValue(value, props) {
|
|
|
17
17
|
return value;
|
|
18
18
|
}
|
|
19
19
|
exports.formatOutgoingCharacteristicValue = formatOutgoingCharacteristicValue;
|
|
20
|
+
/**
|
|
21
|
+
* @group Utils
|
|
22
|
+
*/
|
|
20
23
|
function isNumericFormat(format) {
|
|
21
24
|
switch (format) {
|
|
22
|
-
case "int" /* INT */:
|
|
23
|
-
case "float" /* FLOAT */:
|
|
24
|
-
case "uint8" /* UINT8 */:
|
|
25
|
-
case "uint16" /* UINT16 */:
|
|
26
|
-
case "uint32" /* UINT32 */:
|
|
27
|
-
case "uint64" /* UINT64 */:
|
|
25
|
+
case "int" /* Formats.INT */:
|
|
26
|
+
case "float" /* Formats.FLOAT */:
|
|
27
|
+
case "uint8" /* Formats.UINT8 */:
|
|
28
|
+
case "uint16" /* Formats.UINT16 */:
|
|
29
|
+
case "uint32" /* Formats.UINT32 */:
|
|
30
|
+
case "uint64" /* Formats.UINT64 */:
|
|
28
31
|
return true;
|
|
29
32
|
default:
|
|
30
33
|
return false;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
exports.isNumericFormat = isNumericFormat;
|
|
37
|
+
/**
|
|
38
|
+
* @group Utils
|
|
39
|
+
*/
|
|
34
40
|
function isUnsignedNumericFormat(format) {
|
|
35
41
|
switch (format) {
|
|
36
|
-
case "uint8" /* UINT8 */:
|
|
37
|
-
case "uint16" /* UINT16 */:
|
|
38
|
-
case "uint32" /* UINT32 */:
|
|
39
|
-
case "uint64" /* UINT64 */:
|
|
42
|
+
case "uint8" /* Formats.UINT8 */:
|
|
43
|
+
case "uint16" /* Formats.UINT16 */:
|
|
44
|
+
case "uint32" /* Formats.UINT32 */:
|
|
45
|
+
case "uint64" /* Formats.UINT64 */:
|
|
40
46
|
return true;
|
|
41
47
|
default:
|
|
42
48
|
return false;
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
exports.isUnsignedNumericFormat = isUnsignedNumericFormat;
|
|
52
|
+
/**
|
|
53
|
+
* @group Utils
|
|
54
|
+
*/
|
|
46
55
|
function isIntegerNumericFormat(format) {
|
|
47
56
|
switch (format) {
|
|
48
|
-
case "int" /* INT */:
|
|
49
|
-
case "uint8" /* UINT8 */:
|
|
50
|
-
case "uint16" /* UINT16 */:
|
|
51
|
-
case "uint32" /* UINT32 */:
|
|
52
|
-
case "uint64" /* UINT64 */:
|
|
57
|
+
case "int" /* Formats.INT */:
|
|
58
|
+
case "uint8" /* Formats.UINT8 */:
|
|
59
|
+
case "uint16" /* Formats.UINT16 */:
|
|
60
|
+
case "uint32" /* Formats.UINT32 */:
|
|
61
|
+
case "uint64" /* Formats.UINT64 */:
|
|
53
62
|
return true;
|
|
54
63
|
default:
|
|
55
64
|
return false;
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
exports.isIntegerNumericFormat = isIntegerNumericFormat;
|
|
68
|
+
/**
|
|
69
|
+
* @group Utils
|
|
70
|
+
*/
|
|
59
71
|
function numericLowerBound(format) {
|
|
60
72
|
switch (format) {
|
|
61
|
-
case "int" /* INT */:
|
|
73
|
+
case "int" /* Formats.INT */:
|
|
62
74
|
return -2147483648;
|
|
63
|
-
case "float" /* FLOAT */:
|
|
75
|
+
case "float" /* Formats.FLOAT */:
|
|
64
76
|
return -Number.MAX_VALUE;
|
|
65
|
-
case "uint8" /* UINT8 */:
|
|
66
|
-
case "uint16" /* UINT16 */:
|
|
67
|
-
case "uint32" /* UINT32 */:
|
|
68
|
-
case "uint64" /* UINT64 */:
|
|
77
|
+
case "uint8" /* Formats.UINT8 */:
|
|
78
|
+
case "uint16" /* Formats.UINT16 */:
|
|
79
|
+
case "uint32" /* Formats.UINT32 */:
|
|
80
|
+
case "uint64" /* Formats.UINT64 */:
|
|
69
81
|
return 0;
|
|
70
82
|
default:
|
|
71
83
|
throw new Error("Unable to determine numeric lower bound for " + format);
|
|
72
84
|
}
|
|
73
85
|
}
|
|
74
86
|
exports.numericLowerBound = numericLowerBound;
|
|
87
|
+
/**
|
|
88
|
+
* @group Utils
|
|
89
|
+
*/
|
|
75
90
|
function numericUpperBound(format) {
|
|
76
91
|
switch (format) {
|
|
77
|
-
case "int" /* INT */:
|
|
92
|
+
case "int" /* Formats.INT */:
|
|
78
93
|
return 2147483647;
|
|
79
|
-
case "float" /* FLOAT */:
|
|
94
|
+
case "float" /* Formats.FLOAT */:
|
|
80
95
|
return Number.MAX_VALUE;
|
|
81
|
-
case "uint8" /* UINT8 */:
|
|
96
|
+
case "uint8" /* Formats.UINT8 */:
|
|
82
97
|
return 255;
|
|
83
|
-
case "uint16" /* UINT16 */:
|
|
98
|
+
case "uint16" /* Formats.UINT16 */:
|
|
84
99
|
return 65535;
|
|
85
|
-
case "uint32" /* UINT32 */:
|
|
100
|
+
case "uint32" /* Formats.UINT32 */:
|
|
86
101
|
return 4294967295;
|
|
87
|
-
case "uint64" /* UINT64 */:
|
|
102
|
+
case "uint64" /* Formats.UINT64 */:
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
|
88
104
|
return 18446744073709551615; // don't get fooled, javascript uses 18446744073709552000 here
|
|
89
105
|
default:
|
|
90
106
|
throw new Error("Unable to determine numeric lower bound for " + format);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-util.js","sourceRoot":"","sources":["../../../src/lib/util/request-util.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"request-util.js","sourceRoot":"","sources":["../../../src/lib/util/request-util.ts"],"names":[],"mappings":";;;AAgBA,SAAgB,iCAAiC,CAAC,KAAoC,EAAE,KAA0B;;IAChH,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;QAC9B,OAAO,KAAK,CAAA,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC;KACpB;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,EAAE;YACxC,OAAO,KAAK,CAAC;SACd;QAED,IAAM,IAAI,GAAG,MAAA,KAAK,CAAC,QAAQ,mCAAI,CAAC,CAAC;QACjC,IAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;QAElC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;KAC9F;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAfD,8EAeC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,MAAwB;IACtD,QAAQ,MAAM,EAAE;QAChB,6BAAiB;QACjB,iCAAmB;QACnB,iCAAmB;QACnB,mCAAoB;QACpB,mCAAoB;QACpB;YACE,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAZD,0CAYC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,MAAwB;IAC9D,QAAQ,MAAM,EAAE;QAChB,iCAAmB;QACnB,mCAAoB;QACpB,mCAAoB;QACpB;YACE,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAVD,0DAUC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,MAAwB;IAC7D,QAAQ,MAAM,EAAE;QAChB,6BAAiB;QACjB,iCAAmB;QACnB,mCAAoB;QACpB,mCAAoB;QACpB;YACE,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAXD,wDAWC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,MAAwB;IACxD,QAAQ,MAAM,EAAE;QAChB;YACE,OAAO,CAAC,UAAU,CAAC;QACrB;YACE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;QAC3B,iCAAmB;QACnB,mCAAoB;QACpB,mCAAoB;QACpB;YACE,OAAO,CAAC,CAAC;QACX;YACE,MAAM,IAAI,KAAK,CAAC,8CAA8C,GAAG,MAAM,CAAC,CAAC;KAC1E;AACH,CAAC;AAdD,8CAcC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,MAAwB;IACxD,QAAQ,MAAM,EAAE;QAChB;YACE,OAAO,UAAU,CAAC;QACpB;YACE,OAAO,MAAM,CAAC,SAAS,CAAC;QAC1B;YACE,OAAO,GAAG,CAAC;QACb;YACE,OAAO,KAAK,CAAC;QACf;YACE,OAAO,UAAU,CAAC;QACpB;YACE,mEAAmE;YACnE,OAAO,oBAAoB,CAAC,CAAC,8DAA8D;QAC7F;YACE,MAAM,IAAI,KAAK,CAAC,8CAA8C,GAAG,MAAM,CAAC,CAAC;KAC1E;AACH,CAAC;AAlBD,8CAkBC"}
|
package/dist/lib/util/time.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @group Utils
|
|
4
|
+
*/
|
|
3
5
|
export declare function epochMillisFromMillisSince2001_01_01(millis: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* @group Utils
|
|
8
|
+
*/
|
|
9
|
+
export declare function epochMillisFromMillisSince2001_01_01Buffer(millis: Buffer): number;
|
|
4
10
|
//# sourceMappingURL=time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/lib/util/time.ts"],"names":[],"mappings":";AAKA,wBAAgB,
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/lib/util/time.ts"],"names":[],"mappings":";AAKA;;GAEG;AACH,wBAAgB,oCAAoC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED;;GAEG;AACH,wBAAgB,0CAA0C,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIjF"}
|
package/dist/lib/util/time.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.epochMillisFromMillisSince2001_01_01Buffer = exports.epochMillisFromMillisSince2001_01_01 = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var tlv_1 = require("./tlv");
|
|
7
7
|
var EPOCH_MILLIS_2001_01_01 = Date.UTC(2001, 0, 1, 0, 0, 0, 0);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return epochMillisFromMillisSince2001_01_01(millisSince2001);
|
|
12
|
-
}
|
|
13
|
-
exports.epochMillisFromMillisSince2001_01_01Buffer = epochMillisFromMillisSince2001_01_01Buffer;
|
|
8
|
+
/**
|
|
9
|
+
* @group Utils
|
|
10
|
+
*/
|
|
14
11
|
function epochMillisFromMillisSince2001_01_01(millis) {
|
|
15
12
|
return EPOCH_MILLIS_2001_01_01 + millis;
|
|
16
13
|
}
|
|
17
14
|
exports.epochMillisFromMillisSince2001_01_01 = epochMillisFromMillisSince2001_01_01;
|
|
15
|
+
/**
|
|
16
|
+
* @group Utils
|
|
17
|
+
*/
|
|
18
|
+
function epochMillisFromMillisSince2001_01_01Buffer(millis) {
|
|
19
|
+
(0, assert_1.default)(millis.length === 8, "can only parse 64 bit buffers!");
|
|
20
|
+
var millisSince2001 = (0, tlv_1.readUInt64LE)(millis);
|
|
21
|
+
return epochMillisFromMillisSince2001_01_01(millisSince2001);
|
|
22
|
+
}
|
|
23
|
+
exports.epochMillisFromMillisSince2001_01_01Buffer = epochMillisFromMillisSince2001_01_01Buffer;
|
|
18
24
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../src/lib/util/time.ts"],"names":[],"mappings":";;;;AAAA,0DAA4B;AAC5B,6BAAqC;AAErC,IAAM,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjE,SAAgB,0CAA0C,CAAC,MAAc;IACvE,gBAAM,
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../src/lib/util/time.ts"],"names":[],"mappings":";;;;AAAA,0DAA4B;AAC5B,6BAAqC;AAErC,IAAM,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjE;;GAEG;AACH,SAAgB,oCAAoC,CAAC,MAAc;IACjE,OAAO,uBAAuB,GAAG,MAAM,CAAC;AAC1C,CAAC;AAFD,oFAEC;AAED;;GAEG;AACH,SAAgB,0CAA0C,CAAC,MAAc;IACvE,IAAA,gBAAM,EAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,gCAAgC,CAAC,CAAC;IAC9D,IAAM,eAAe,GAAG,IAAA,kBAAY,EAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,oCAAoC,CAAC,eAAe,CAAC,CAAC;AAC/D,CAAC;AAJD,gGAIC"}
|
package/dist/lib/util/tlv.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @group TLV8
|
|
4
|
+
*/
|
|
5
|
+
export type TLVEncodable = Buffer | number | string;
|
|
6
|
+
/**
|
|
7
|
+
* @group TLV8
|
|
8
|
+
*/
|
|
3
9
|
export declare function encode(type: number, data: TLVEncodable | TLVEncodable[], ...args: any[]): Buffer;
|
|
4
10
|
/**
|
|
5
11
|
* This method is the legacy way of decoding tlv data.
|
|
@@ -7,22 +13,106 @@ export declare function encode(type: number, data: TLVEncodable | TLVEncodable[]
|
|
|
7
13
|
* Should the decoder encounter multiple instances of the same id, it will just concatenate the buffer data.
|
|
8
14
|
*
|
|
9
15
|
* @param buffer - TLV8 data
|
|
16
|
+
*
|
|
17
|
+
* Note: Please use {@link decodeWithLists} which properly decodes list elements.
|
|
18
|
+
*
|
|
19
|
+
* @group TLV8
|
|
10
20
|
*/
|
|
11
21
|
export declare function decode(buffer: Buffer): Record<number, Buffer>;
|
|
22
|
+
/**
|
|
23
|
+
* Decode a buffer coding TLV8 encoded entries.
|
|
24
|
+
*
|
|
25
|
+
* This method decodes multiple entries split by a TLV delimiter properly into Buffer arrays.
|
|
26
|
+
* It properly reassembles tlv entries if they were split across multiple entries due to exceeding the max tlv entry size of 255 bytes.
|
|
27
|
+
* @param buffer - The Buffer containing TLV8 encoded data.
|
|
28
|
+
*
|
|
29
|
+
* @group TLV8
|
|
30
|
+
*/
|
|
12
31
|
export declare function decodeWithLists(buffer: Buffer): Record<number, Buffer | Buffer[]>;
|
|
32
|
+
/**
|
|
33
|
+
* This method can be used to parse a TLV8 encoded list that was concatenated.
|
|
34
|
+
*
|
|
35
|
+
* If you are thinking about using this method, try to refactor the code to use {@link decodeWithLists} instead of {@link decode}.
|
|
36
|
+
* The single reason of this method's existence are the shortcomings {@link decode}, as it concatenates multiple tlv8 list entries
|
|
37
|
+
* into a single Buffer.
|
|
38
|
+
* This method can be used to undo that, by specifying the concatenated buffer and the tlv id of the element that should
|
|
39
|
+
* mark the beginning of a new tlv8 list entry.
|
|
40
|
+
*
|
|
41
|
+
* @param data - The concatenated tlv8 list entries (probably output of {@link decode}).
|
|
42
|
+
* @param entryStartId - The tlv id that marks the beginning of a new tlv8 entry.
|
|
43
|
+
*
|
|
44
|
+
* @group TLV8
|
|
45
|
+
*/
|
|
13
46
|
export declare function decodeList(data: Buffer, entryStartId: number): Record<number, Buffer>[];
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated This implementation is considered broken. Don't use it.
|
|
49
|
+
*
|
|
50
|
+
* @group TLV8
|
|
51
|
+
*/
|
|
14
52
|
export declare function writeUInt64(value: number): Buffer;
|
|
15
53
|
/**
|
|
16
|
-
* @
|
|
17
|
-
*
|
|
54
|
+
* @deprecated This implementation is considered broken. Don't use it.
|
|
55
|
+
*
|
|
56
|
+
* @group TLV8
|
|
18
57
|
*/
|
|
19
58
|
export declare function readUInt64(buffer: Buffer): number;
|
|
59
|
+
/**
|
|
60
|
+
* @group TLV8
|
|
61
|
+
*/
|
|
62
|
+
export declare function readUInt64LE(buffer: Buffer, offset?: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated The method was named wrongfully and actually reads an UInt64 in **little endian** format.
|
|
65
|
+
* @group TLV8
|
|
66
|
+
*/
|
|
20
67
|
export declare function readUInt64BE(buffer: Buffer, offset?: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* `writeUint32LE`
|
|
70
|
+
* @group TLV8
|
|
71
|
+
*/
|
|
21
72
|
export declare function writeUInt32(value: number): Buffer;
|
|
73
|
+
/**
|
|
74
|
+
* `readUInt32LE`
|
|
75
|
+
* @group TLV8
|
|
76
|
+
*/
|
|
22
77
|
export declare function readUInt32(buffer: Buffer): number;
|
|
78
|
+
/**
|
|
79
|
+
* @group TLV8
|
|
80
|
+
*/
|
|
23
81
|
export declare function writeFloat32LE(value: number): Buffer;
|
|
82
|
+
/**
|
|
83
|
+
* `writeUInt16LE`
|
|
84
|
+
* @group TLV8
|
|
85
|
+
*/
|
|
24
86
|
export declare function writeUInt16(value: number): Buffer;
|
|
87
|
+
/**
|
|
88
|
+
* `readUInt16LE`
|
|
89
|
+
* @group TLV8
|
|
90
|
+
*/
|
|
25
91
|
export declare function readUInt16(buffer: Buffer): number;
|
|
26
|
-
|
|
27
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Reads variable size unsigned integer {@link writeVariableUIntLE}.
|
|
94
|
+
* @param buffer - The buffer to read from. It must have exactly the size of the given integer.
|
|
95
|
+
* @group TLV8
|
|
96
|
+
*/
|
|
97
|
+
export declare function readVariableUIntLE(buffer: Buffer): number;
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated Can't define an offset. The original implementation messed up here!
|
|
100
|
+
* @group TLV8
|
|
101
|
+
*/
|
|
102
|
+
export declare function readVariableUIntLE(buffer: Buffer, offset: number): number;
|
|
103
|
+
/**
|
|
104
|
+
* Writes variable size unsigned integer.
|
|
105
|
+
* Either:
|
|
106
|
+
* - `UInt8`
|
|
107
|
+
* - `UInt16LE`
|
|
108
|
+
* - `UInt32LE`
|
|
109
|
+
* @param number
|
|
110
|
+
* @group TLV8
|
|
111
|
+
*/
|
|
112
|
+
export declare function writeVariableUIntLE(number: number): Buffer;
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Can't define an offset. The original implementation messed up here!
|
|
115
|
+
* @group TLV8
|
|
116
|
+
*/
|
|
117
|
+
export declare function writeVariableUIntLE(number: number, offset: number): Buffer;
|
|
28
118
|
//# sourceMappingURL=tlv.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tlv.d.ts","sourceRoot":"","sources":["../../../src/lib/util/tlv.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tlv.d.ts","sourceRoot":"","sources":["../../../src/lib/util/tlv.ts"],"names":[],"mappings":";AAUA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD;;GAEG;AAEH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAsDhG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0B7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAsDjF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAwCvF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWjD;AAGD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,MAAM,CAI/D;AAGD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,MAAM,CAE/D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIpD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAGD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;AAC3D;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;AAkB3E;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAK,MAAM,CAAC;AAC9D;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC"}
|
package/dist/lib/util/tlv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeVariableUIntLE = exports.readVariableUIntLE = exports.readUInt16 = exports.writeUInt16 = exports.writeFloat32LE = exports.readUInt32 = exports.writeUInt32 = exports.readUInt64BE = exports.readUInt64 = exports.writeUInt64 = exports.decodeList = exports.decodeWithLists = exports.decode = exports.encode = void 0;
|
|
3
|
+
exports.writeVariableUIntLE = exports.readVariableUIntLE = exports.readUInt16 = exports.writeUInt16 = exports.writeFloat32LE = exports.readUInt32 = exports.writeUInt32 = exports.readUInt64BE = exports.readUInt64LE = exports.readUInt64 = exports.writeUInt64 = exports.decodeList = exports.decodeWithLists = exports.decode = exports.encode = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var hapCrypto = tslib_1.__importStar(require("../util/hapCrypto"));
|
|
@@ -9,6 +9,10 @@ var hapCrypto = tslib_1.__importStar(require("../util/hapCrypto"));
|
|
|
9
9
|
* https://en.wikipedia.org/wiki/Type-length-value
|
|
10
10
|
*/
|
|
11
11
|
var EMPTY_TLV_TYPE = 0x00; // and empty tlv with id 0 is usually used as delimiter for tlv lists
|
|
12
|
+
/**
|
|
13
|
+
* @group TLV8
|
|
14
|
+
*/
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
16
|
function encode(type, data) {
|
|
13
17
|
var e_1, _a;
|
|
14
18
|
var args = [];
|
|
@@ -17,10 +21,10 @@ function encode(type, data) {
|
|
|
17
21
|
}
|
|
18
22
|
var encodedTLVBuffers = [];
|
|
19
23
|
// coerce data to Buffer if needed
|
|
20
|
-
if (typeof data ===
|
|
24
|
+
if (typeof data === "number") {
|
|
21
25
|
data = Buffer.from([data]);
|
|
22
26
|
}
|
|
23
|
-
else if (typeof data ===
|
|
27
|
+
else if (typeof data === "string") {
|
|
24
28
|
data = Buffer.from(data);
|
|
25
29
|
}
|
|
26
30
|
if (Array.isArray(data)) {
|
|
@@ -31,9 +35,7 @@ function encode(type, data) {
|
|
|
31
35
|
if (!first) {
|
|
32
36
|
encodedTLVBuffers.push(Buffer.from([EMPTY_TLV_TYPE, 0])); // push delimiter
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
first = false;
|
|
36
|
-
}
|
|
38
|
+
first = false;
|
|
37
39
|
encodedTLVBuffers.push(encode(type, entry));
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -44,6 +46,9 @@ function encode(type, data) {
|
|
|
44
46
|
}
|
|
45
47
|
finally { if (e_1) throw e_1.error; }
|
|
46
48
|
}
|
|
49
|
+
if (first) { // we have a zero length array!
|
|
50
|
+
encodedTLVBuffers.push(Buffer.from([type, 0]));
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
else if (data.length <= 255) {
|
|
49
54
|
encodedTLVBuffers.push(Buffer.concat([Buffer.from([type, data.length]), data]));
|
|
@@ -67,7 +72,7 @@ function encode(type, data) {
|
|
|
67
72
|
if (args.length >= 2) {
|
|
68
73
|
// chop off the first two arguments which we already processed, and process the rest recursively
|
|
69
74
|
var _b = tslib_1.__read(args), nextType = _b[0], nextData = _b[1], nextArgs = _b.slice(2);
|
|
70
|
-
var remainingTLVBuffer = encode.apply(void 0, tslib_1.__spreadArray([nextType, nextData], tslib_1.__read(nextArgs)));
|
|
75
|
+
var remainingTLVBuffer = encode.apply(void 0, tslib_1.__spreadArray([nextType, nextData], tslib_1.__read(nextArgs), false));
|
|
71
76
|
// append the remaining encoded arguments directly to the buffer
|
|
72
77
|
encodedTLVBuffers.push(remainingTLVBuffer);
|
|
73
78
|
}
|
|
@@ -80,8 +85,13 @@ exports.encode = encode;
|
|
|
80
85
|
* Should the decoder encounter multiple instances of the same id, it will just concatenate the buffer data.
|
|
81
86
|
*
|
|
82
87
|
* @param buffer - TLV8 data
|
|
88
|
+
*
|
|
89
|
+
* Note: Please use {@link decodeWithLists} which properly decodes list elements.
|
|
90
|
+
*
|
|
91
|
+
* @group TLV8
|
|
83
92
|
*/
|
|
84
93
|
function decode(buffer) {
|
|
94
|
+
(0, assert_1.default)(buffer instanceof Buffer, "Illegal argument. tlv.decode() expects Buffer type!");
|
|
85
95
|
var objects = {};
|
|
86
96
|
var leftLength = buffer.length;
|
|
87
97
|
var currentIndex = 0;
|
|
@@ -103,6 +113,15 @@ function decode(buffer) {
|
|
|
103
113
|
return objects;
|
|
104
114
|
}
|
|
105
115
|
exports.decode = decode;
|
|
116
|
+
/**
|
|
117
|
+
* Decode a buffer coding TLV8 encoded entries.
|
|
118
|
+
*
|
|
119
|
+
* This method decodes multiple entries split by a TLV delimiter properly into Buffer arrays.
|
|
120
|
+
* It properly reassembles tlv entries if they were split across multiple entries due to exceeding the max tlv entry size of 255 bytes.
|
|
121
|
+
* @param buffer - The Buffer containing TLV8 encoded data.
|
|
122
|
+
*
|
|
123
|
+
* @group TLV8
|
|
124
|
+
*/
|
|
106
125
|
function decodeWithLists(buffer) {
|
|
107
126
|
var result = {};
|
|
108
127
|
var leftBytes = buffer.length;
|
|
@@ -142,7 +161,7 @@ function decodeWithLists(buffer) {
|
|
|
142
161
|
}
|
|
143
162
|
}
|
|
144
163
|
else {
|
|
145
|
-
throw new Error("Found duplicated tlv entry with type "
|
|
164
|
+
throw new Error("Found duplicated tlv entry with type ".concat(type, " and length ").concat(length, " (lastItemWasDelimiter: ").concat(lastItemWasDelimiter, ", lastType: ").concat(lastType, ", lastLength: ").concat(lastLength, ")"));
|
|
146
165
|
}
|
|
147
166
|
}
|
|
148
167
|
else {
|
|
@@ -155,6 +174,20 @@ function decodeWithLists(buffer) {
|
|
|
155
174
|
return result;
|
|
156
175
|
}
|
|
157
176
|
exports.decodeWithLists = decodeWithLists;
|
|
177
|
+
/**
|
|
178
|
+
* This method can be used to parse a TLV8 encoded list that was concatenated.
|
|
179
|
+
*
|
|
180
|
+
* If you are thinking about using this method, try to refactor the code to use {@link decodeWithLists} instead of {@link decode}.
|
|
181
|
+
* The single reason of this method's existence are the shortcomings {@link decode}, as it concatenates multiple tlv8 list entries
|
|
182
|
+
* into a single Buffer.
|
|
183
|
+
* This method can be used to undo that, by specifying the concatenated buffer and the tlv id of the element that should
|
|
184
|
+
* mark the beginning of a new tlv8 list entry.
|
|
185
|
+
*
|
|
186
|
+
* @param data - The concatenated tlv8 list entries (probably output of {@link decode}).
|
|
187
|
+
* @param entryStartId - The tlv id that marks the beginning of a new tlv8 entry.
|
|
188
|
+
*
|
|
189
|
+
* @group TLV8
|
|
190
|
+
*/
|
|
158
191
|
function decodeList(data, entryStartId) {
|
|
159
192
|
var objectsList = [];
|
|
160
193
|
var leftLength = data.length;
|
|
@@ -170,10 +203,11 @@ function decodeList(data, entryStartId) {
|
|
|
170
203
|
}
|
|
171
204
|
objects = {};
|
|
172
205
|
}
|
|
173
|
-
if (objects === undefined)
|
|
206
|
+
if (objects === undefined) {
|
|
174
207
|
throw new Error("Error parsing tlv list: Encountered uninitialized storage object");
|
|
175
|
-
|
|
176
|
-
|
|
208
|
+
}
|
|
209
|
+
if (objects[type]) { // append to buffer if we have already data for this type
|
|
210
|
+
objects[type] = Buffer.concat([objects[type], value]);
|
|
177
211
|
}
|
|
178
212
|
else {
|
|
179
213
|
objects[type] = value;
|
|
@@ -181,11 +215,17 @@ function decodeList(data, entryStartId) {
|
|
|
181
215
|
currentIndex += 2 + length;
|
|
182
216
|
leftLength -= 2 + length;
|
|
183
217
|
}
|
|
184
|
-
if (objects !== undefined)
|
|
185
|
-
objectsList.push(objects);
|
|
218
|
+
if (objects !== undefined) {
|
|
219
|
+
objectsList.push(objects);
|
|
220
|
+
} // push last entry
|
|
186
221
|
return objectsList;
|
|
187
222
|
}
|
|
188
223
|
exports.decodeList = decodeList;
|
|
224
|
+
/**
|
|
225
|
+
* @deprecated This implementation is considered broken. Don't use it.
|
|
226
|
+
*
|
|
227
|
+
* @group TLV8
|
|
228
|
+
*/
|
|
189
229
|
function writeUInt64(value) {
|
|
190
230
|
var float64 = new Float64Array(1);
|
|
191
231
|
float64[0] = value;
|
|
@@ -199,48 +239,83 @@ function writeUInt64(value) {
|
|
|
199
239
|
exports.writeUInt64 = writeUInt64;
|
|
200
240
|
// noinspection JSUnusedGlobalSymbols
|
|
201
241
|
/**
|
|
202
|
-
* @
|
|
203
|
-
*
|
|
242
|
+
* @deprecated This implementation is considered broken. Don't use it.
|
|
243
|
+
*
|
|
244
|
+
* @group TLV8
|
|
204
245
|
*/
|
|
205
246
|
function readUInt64(buffer) {
|
|
206
247
|
var float64 = new Float64Array(buffer);
|
|
207
248
|
return float64[0];
|
|
208
249
|
}
|
|
209
250
|
exports.readUInt64 = readUInt64;
|
|
210
|
-
|
|
251
|
+
/**
|
|
252
|
+
* @group TLV8
|
|
253
|
+
*/
|
|
254
|
+
function readUInt64LE(buffer, offset) {
|
|
211
255
|
if (offset === void 0) { offset = 0; }
|
|
212
256
|
var low = buffer.readUInt32LE(offset);
|
|
257
|
+
// javascript doesn't allow to shift by 32(?), therefore we multiply here
|
|
213
258
|
return buffer.readUInt32LE(offset + 4) * 0x100000000 + low;
|
|
214
259
|
}
|
|
260
|
+
exports.readUInt64LE = readUInt64LE;
|
|
261
|
+
// noinspection JSUnusedGlobalSymbols
|
|
262
|
+
/**
|
|
263
|
+
* @deprecated The method was named wrongfully and actually reads an UInt64 in **little endian** format.
|
|
264
|
+
* @group TLV8
|
|
265
|
+
*/
|
|
266
|
+
function readUInt64BE(buffer, offset) {
|
|
267
|
+
if (offset === void 0) { offset = 0; }
|
|
268
|
+
return readUInt64LE(buffer, offset);
|
|
269
|
+
}
|
|
215
270
|
exports.readUInt64BE = readUInt64BE;
|
|
271
|
+
/**
|
|
272
|
+
* `writeUint32LE`
|
|
273
|
+
* @group TLV8
|
|
274
|
+
*/
|
|
216
275
|
function writeUInt32(value) {
|
|
217
276
|
var buffer = Buffer.alloc(4);
|
|
218
277
|
buffer.writeUInt32LE(value, 0);
|
|
219
278
|
return buffer;
|
|
220
279
|
}
|
|
221
280
|
exports.writeUInt32 = writeUInt32;
|
|
281
|
+
/**
|
|
282
|
+
* `readUInt32LE`
|
|
283
|
+
* @group TLV8
|
|
284
|
+
*/
|
|
222
285
|
function readUInt32(buffer) {
|
|
223
286
|
return buffer.readUInt32LE(0);
|
|
224
287
|
}
|
|
225
288
|
exports.readUInt32 = readUInt32;
|
|
289
|
+
/**
|
|
290
|
+
* @group TLV8
|
|
291
|
+
*/
|
|
226
292
|
function writeFloat32LE(value) {
|
|
227
293
|
var buffer = Buffer.alloc(4);
|
|
228
294
|
buffer.writeFloatLE(value, 0);
|
|
229
295
|
return buffer;
|
|
230
296
|
}
|
|
231
297
|
exports.writeFloat32LE = writeFloat32LE;
|
|
298
|
+
/**
|
|
299
|
+
* `writeUInt16LE`
|
|
300
|
+
* @group TLV8
|
|
301
|
+
*/
|
|
232
302
|
function writeUInt16(value) {
|
|
233
303
|
var buffer = Buffer.alloc(2);
|
|
234
304
|
buffer.writeUInt16LE(value, 0);
|
|
235
305
|
return buffer;
|
|
236
306
|
}
|
|
237
307
|
exports.writeUInt16 = writeUInt16;
|
|
308
|
+
/**
|
|
309
|
+
* `readUInt16LE`
|
|
310
|
+
* @group TLV8
|
|
311
|
+
*/
|
|
238
312
|
function readUInt16(buffer) {
|
|
239
313
|
return buffer.readUInt16LE(0);
|
|
240
314
|
}
|
|
241
315
|
exports.readUInt16 = readUInt16;
|
|
242
316
|
function readVariableUIntLE(buffer, offset) {
|
|
243
317
|
if (offset === void 0) { offset = 0; }
|
|
318
|
+
(0, assert_1.default)(offset === 0, "Can't define a offset different than 0!");
|
|
244
319
|
switch (buffer.length) {
|
|
245
320
|
case 1:
|
|
246
321
|
return buffer.readUInt8(offset);
|
|
@@ -249,7 +324,7 @@ function readVariableUIntLE(buffer, offset) {
|
|
|
249
324
|
case 4:
|
|
250
325
|
return buffer.readUInt32LE(offset);
|
|
251
326
|
case 8:
|
|
252
|
-
return
|
|
327
|
+
return readUInt64LE(buffer, offset);
|
|
253
328
|
default:
|
|
254
329
|
throw new Error("Can't read uint LE with length " + buffer.length);
|
|
255
330
|
}
|
|
@@ -257,21 +332,18 @@ function readVariableUIntLE(buffer, offset) {
|
|
|
257
332
|
exports.readVariableUIntLE = readVariableUIntLE;
|
|
258
333
|
function writeVariableUIntLE(number, offset) {
|
|
259
334
|
if (offset === void 0) { offset = 0; }
|
|
260
|
-
assert_1.default(number >= 0, "Can't encode a negative integer as unsigned integer");
|
|
335
|
+
(0, assert_1.default)(number >= 0, "Can't encode a negative integer as unsigned integer");
|
|
336
|
+
(0, assert_1.default)(offset === 0, "Can't define a offset different than 0!");
|
|
261
337
|
if (number <= 255) {
|
|
262
338
|
var buffer = Buffer.alloc(1);
|
|
263
339
|
buffer.writeUInt8(number, offset);
|
|
264
340
|
return buffer;
|
|
265
341
|
}
|
|
266
342
|
else if (number <= 65535) {
|
|
267
|
-
|
|
268
|
-
buffer.writeUInt16LE(number, offset);
|
|
269
|
-
return buffer;
|
|
343
|
+
return writeUInt16(number);
|
|
270
344
|
}
|
|
271
345
|
else if (number <= 4294967295) {
|
|
272
|
-
|
|
273
|
-
buffer.writeUInt32LE(number, offset);
|
|
274
|
-
return buffer;
|
|
346
|
+
return writeUInt32(number);
|
|
275
347
|
}
|
|
276
348
|
else {
|
|
277
349
|
var buffer = Buffer.alloc(8);
|