UNPKG

xiot-core-spec-ts

Version:
33 lines (32 loc) 963 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DescriptionCodec = void 0; const Spec_1 = require("../../typedef/constant/Spec"); class DescriptionCodec { static decode(o) { const description = new Map(); if (typeof o === 'string') { description.set(Spec_1.Spec.EN_US, o); } else if (typeof o === 'object') { Object.keys(o).forEach(x => { description.set(x.toString(), o[x]); }); } return description; } static encode(description) { if (description.size === 0) { return ''; } if (description.size === 1) { return description.get(Spec_1.Spec.EN_US); } const o = Object.create(null); description.forEach((value, key) => { o[key.toString()] = value; }); return o; } } exports.DescriptionCodec = DescriptionCodec;