UNPKG

xiot-core-spec-ts

Version:
83 lines (82 loc) 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SummaryCodec = void 0; const Summary_1 = require("../../typedef/summary/Summary"); const Urn_1 = require("../../typedef/definition/urn/Urn"); const UrnType_1 = require("../../typedef/definition/urn/UrnType"); class SummaryCodec { static decodeArray(list) { const array = []; if (list != null) { for (const o of list) { array.push(SummaryCodec.decodeObject(o)); } } return array; } static decodeObject(o) { const summary = new Summary_1.Summary(); summary.type = new Urn_1.Urn([UrnType_1.UrnType.DEVICE, UrnType_1.UrnType.GROUP], o.type); summary.online = o.online; if (o.members !== undefined) { summary.members = o.members; } if (o.cloudId !== undefined) { summary.cloudId = o.cloudId; } if (o.parentId !== undefined) { summary.parentId = o.parentId; } if (o.rootId !== undefined) { summary.rootId = o.rootId; } if (o.protocol !== undefined) { summary.protocol = o.protocol; } if (o.lastOnline !== undefined) { summary.lastOnline = new Date(o.lastOnline); } if (o.lastOffline !== undefined) { summary.lastOffline = new Date(o.lastOffline); } return summary; } static encodeObject(s) { const o = { type: s.type != null ? s.type.toString() : '', online: s.online }; if (s.parentId != null) { o.parentId = s.parentId; } if (s.cloudId != null) { o.cloudId = s.cloudId; } if (s.members != null) { if (s.members.length > 0) { o.members = s.members; } } if (s.rootId != null) { o.rootId = s.rootId; } if (s.protocol != null) { o.protocol = s.protocol; } if (s.lastOnline !== undefined) { o.lastOnline = s.lastOnline.getTime(); } if (s.lastOffline !== undefined) { o.lastOffline = s.lastOffline.getTime(); } return o; } static encodeArray(array) { return array != null ? array.map(s => { return SummaryCodec.encodeObject(s); }) : []; } } exports.SummaryCodec = SummaryCodec;