@softchef/cdk-iot-device-management
Version:
IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.
46 lines (45 loc) • 1.39 kB
JavaScript
import { toHex } from "@aws-sdk/util-hex-encoding";
var Int64 = (function () {
function Int64(bytes) {
this.bytes = bytes;
if (bytes.byteLength !== 8) {
throw new Error("Int64 buffers must be exactly 8 bytes");
}
}
Int64.fromNumber = function (number) {
if (number > 9223372036854775807 || number < -9223372036854775808) {
throw new Error(number + " is too large (or, if negative, too small) to represent as an Int64");
}
var bytes = new Uint8Array(8);
for (var i = 7, remaining = Math.abs(Math.round(number)); i > -1 && remaining > 0; i--, remaining /= 256) {
bytes[i] = remaining;
}
if (number < 0) {
negate(bytes);
}
return new Int64(bytes);
};
Int64.prototype.valueOf = function () {
var bytes = this.bytes.slice(0);
var negative = bytes[0] & 128;
if (negative) {
negate(bytes);
}
return parseInt(toHex(bytes), 16) * (negative ? -1 : 1);
};
Int64.prototype.toString = function () {
return String(this.valueOf());
};
return Int64;
}());
export { Int64 };
function negate(bytes) {
for (var i = 0; i < 8; i++) {
bytes[i] ^= 0xff;
}
for (var i = 7; i > -1; i--) {
bytes[i]++;
if (bytes[i] !== 0)
break;
}
}