UNPKG

xiot-core-spec-ts

Version:
52 lines (51 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceCodec = void 0; const Device_1 = require("../../typedef/device/Device"); const SummaryCodec_1 = require("../summary/SummaryCodec"); const SomewhereCodec_1 = require("../somewhere/SomewhereCodec"); class DeviceCodec { static decodeArray(array) { return array ? array.map(x => { return DeviceCodec.decode(x); }) : []; } static decode(o) { const device = new Device_1.Device(o.did || ''); if (o.summary) { device.summary = SummaryCodec_1.SummaryCodec.decodeObject(o.summary); } if (o.somewhere) { device.somewhere = SomewhereCodec_1.SomewhereCodec.decodeObject(o.somewhere); } if (o.token) { device.token = o.token; } return device; } static encode(device) { const res = { did: device.did }; if (device.summary) { res.summary = SummaryCodec_1.SummaryCodec.encodeObject(device.summary); } if (device.somewhere) { res.somewhere = SomewhereCodec_1.SomewhereCodec.encodeObject(device.somewhere); } if (device.token) { res.token = device.token; } return res; } static encodeArray(children) { return children != null ? children.map(s => { return DeviceCodec.encode(s); }) : []; } } exports.DeviceCodec = DeviceCodec;