xiot-core-spec-ts
Version:
XIOT Specification Codec
52 lines (51 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShadowCodec = void 0;
const Shadow_1 = require("../../typedef/shadow/Shadow");
const Spec_1 = require("../../typedef/constant/Spec");
class ShadowCodec {
static decodeArray(list) {
const array = [];
if (list != null) {
for (const o of list) {
array.push(ShadowCodec.decodeObject(o));
}
}
return array;
}
static decodeObject(o) {
const shadow = new Shadow_1.Shadow();
shadow.siid = o[Spec_1.Spec.SIID] || 0;
shadow.piid = o[Spec_1.Spec.PIID] || 0;
shadow.status = o[Spec_1.Spec.STATUS] || 0;
if (shadow.status >= 0) {
shadow.value = o[Spec_1.Spec.VALUE];
}
else {
shadow.description = o[Spec_1.Spec.DESCRIPTION] || '';
}
return shadow;
}
static encodeObject(s) {
const o = {
siid: s.siid,
piid: s.piid,
status: s.status
};
if (s.status >= 0) {
o[Spec_1.Spec.VALUE] = s.value;
}
else {
o[Spec_1.Spec.DESCRIPTION] = s.description;
}
return o;
}
static encodeArray(array) {
return array != null
? array.map(s => {
return ShadowCodec.encodeObject(s);
})
: [];
}
}
exports.ShadowCodec = ShadowCodec;