UNPKG

xiot-core-spec-ts

Version:
45 lines (44 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArgumentCodec = void 0; const Spec_1 = require("../../typedef/constant/Spec"); const Argument_1 = require("../../typedef/instance/Argument"); class ArgumentCodec { static decodeArray(list) { const array = []; if (list != null) { list.forEach(o => { const a = ArgumentCodec.decode(o); if (a != null) { array.push(a); } }); } return array; } static decode(o) { if (typeof o === 'number') { return new Argument_1.Argument(o); } const piid = o[Spec_1.Spec.PIID]; const def = new Argument_1.Argument(piid); const repeat = o[Spec_1.Spec.REPEAT]; if (repeat != null) { def.minRepeat = repeat[0]; def.maxRepeat = repeat[1]; } return def; } static encode(def) { return { piid: def.piid, repeat: [def.minRepeat, def.maxRepeat] }; } static encodeArray(list) { return list.map(x => { return ArgumentCodec.encode(x); }); } } exports.ArgumentCodec = ArgumentCodec;