UNPKG

xiot-core-spec-ts

Version:
39 lines (38 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceShadowCodec = void 0; const DeviceShadow_1 = require("../../typedef/shadow/DeviceShadow"); const ShadowCodec_1 = require("./ShadowCodec"); class DeviceShadowCodec { static encode(x) { return { did: x.did, shadows: ShadowCodec_1.ShadowCodec.encodeArray(x.shadows) }; } static decode(o) { const device = new DeviceShadow_1.DeviceShadow(); device.did = o.did; device.shadows = ShadowCodec_1.ShadowCodec.decodeArray(o.shadows); return device; } static encodeArray(arr) { const list = []; if (arr === null || arr === void 0 ? void 0 : arr.length) { for (const o of arr) { list.push(this.encode(o)); } } return list; } static decodeArray(arr) { const instances = []; if (arr === null || arr === void 0 ? void 0 : arr.length) { for (const o of arr) { instances.push(this.decode(o)); } } return instances; } } exports.DeviceShadowCodec = DeviceShadowCodec;