xiot-core-spec-ts
Version:
XIOT Specification Codec
66 lines (65 loc) • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Urn_1 = require("../../typedef/definition/urn/Urn");
const Summary_1 = require("../../typedef/summary/Summary");
const UrnType_1 = require("../../typedef/definition/urn/UrnType");
const Protocol_1 = require("../../typedef/protocol/Protocol");
class SummaryCodec {
static decodeArray(json) {
const array = [];
const devices = json['devices'];
if (devices != null) {
if (devices instanceof Array) {
for (const device of devices) {
array.push(SummaryCodec.decodeObject(device));
}
}
}
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'];
summary.protocol = Protocol_1.ProtocolFromString(o['protocol']);
summary.groups = o['groups'];
summary.cloudId = o['cloudId'];
summary.parentId = o['parentId'];
summary.interoperations = o['interoperations'];
summary.accesspoint = o['accesspoint'];
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.groups != null) {
o.groups = s.groups;
}
if (s.interoperations != null) {
o.interoperations = s.interoperations;
}
if (s.protocol != null) {
if (s.protocol !== Protocol_1.Protocol.UNDEFINED) {
o.protocol = s.protocol;
}
}
if (s.accesspoint != null) {
o.accesspoint = s.accesspoint;
}
return o;
}
static encodeArray(summaries) {
return {
devices: (summaries != null) ? summaries.map(s => SummaryCodec.encodeObject(s)) : []
};
}
}
exports.SummaryCodec = SummaryCodec;