xiot-core-spec-ts
Version:
XIOT Specification Codec
30 lines (29 loc) • 904 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
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 Array.from(description.values())[0];
}
const o = Object.create(null);
description.forEach((value, key) => o[key.toString()] = value);
return o;
}
}
exports.DescriptionCodec = DescriptionCodec;