UNPKG

domotz-remote-pawn

Version:

Domotz Agent

95 lines (90 loc) 2.71 kB
/** This file is part of Domotz Agent. * Copyright (C) 2016 Domotz UK LLP * * Domotz Agent is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Domotz Agent is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>. **/ /** * * @deprecated * USE src/snmp/common.js INSTEAD */ /** * * Created by Iacopo Papalini <iacopo@domotz.com> on 11/04/16. */ module.exports.transformer = function (value) { 'use strict'; return { string: function (o) { // https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings try { var s = '' + o; if (s.indexOf('\uFFFD') === -1) { return s; } else { return o .toString('hex') .match(/.{1,2}/g) .join(' ') .toUpperCase(); } } catch (e) { return '' + o; } }, mac: function (o) { var byteList = []; for (var i = 0; i < o.length; i++) { var tmpByte = o.readUInt8(i); var tmpStr = tmpByte.toString(16); if (tmpStr.length < 2) { tmpStr = '0' + tmpStr; } byteList.push(tmpStr); } return byteList.join(':').toUpperCase(); }, int: function (o) { return o; }, }[value]; }; module.exports.extractOids = function (oidsMapping) { 'use strict'; var oids = []; for (var oid in oidsMapping) { if (oidsMapping.hasOwnProperty(oid)) { oids.push(oid); } } return oids; }; module.exports.isEmpty = function (obj) { for (var prop in obj) { if (obj.hasOwnProperty(prop)) { return false; } } return JSON.stringify(obj) === JSON.stringify({}); }; module.exports.extractFromOptions = function (options, field, defaultValue) { var value; if (options[field]) { value = options[field]; delete options[field]; } else { value = defaultValue; } return value; };