@iotize/device-client.js
Version:
IoTize Device client for Javascript
40 lines (39 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("../../../../core");
var error_1 = require("../../../api/converter/error");
var MacAddressStringConverter = /** @class */ (function () {
function MacAddressStringConverter() {
}
MacAddressStringConverter.prototype.decode = function (body) {
if (body == null || body.length != MacAddressStringConverter.EXPECTED_ARRAY_LENGTH) {
throw error_1.ConverterError.unexpectedBufferSize(MacAddressStringConverter.EXPECTED_ARRAY_LENGTH, body);
}
var result = "";
for (var i = 0; i < body.length; i++) {
var part = body.slice(i, i + 1);
result += core_1.FormatHelper.toHexString(part).toUpperCase() + ":";
}
return result.substr(0, result.length - 1);
};
MacAddressStringConverter.prototype.encode = function (value) {
var parts = value.split(":");
if (parts.length != 6) {
throw new Error("Invalid mac address format: " + value);
}
var result = new Uint8Array(parts.length);
parts.map(function (value, index) {
result[index] = parseInt(value) & 0xFF;
});
return result;
};
MacAddressStringConverter.instance = function () {
if (!MacAddressStringConverter._instance) {
MacAddressStringConverter._instance = new MacAddressStringConverter();
}
return MacAddressStringConverter._instance;
};
MacAddressStringConverter.EXPECTED_ARRAY_LENGTH = 6;
return MacAddressStringConverter;
}());
exports.MacAddressStringConverter = MacAddressStringConverter;