xiot-core-spec-ts
Version:
XIOT Specification Codec
40 lines (39 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ArgumentDefinition_1 = require("../../typedef/definition/ArgumentDefinition");
const PropertyType_1 = require("../../typedef/definition/urn/PropertyType");
const Spec_1 = require("../../typedef/constant/Spec");
class ArgumentDefinitionCodec {
static decodeArray(list) {
const array = [];
if (list != null) {
list.forEach(o => {
const def = ArgumentDefinitionCodec.decode(o);
if (def != null) {
array.push(def);
}
});
}
return array;
}
static decode(o) {
const type = (typeof o === 'string') ? new PropertyType_1.PropertyType(o) : new PropertyType_1.PropertyType(o[Spec_1.Spec.PROPERTY]);
const def = new ArgumentDefinition_1.ArgumentDefinition(type);
const repeat = o[Spec_1.Spec.REPEAT];
if (repeat != null) {
def.minRepeat = repeat[0];
def.maxRepeat = repeat[1];
}
return def;
}
static encode(def) {
return {
property: def.type.toString(),
repeat: [def.minRepeat, def.maxRepeat]
};
}
static encodeArray(list) {
return list.map(x => ArgumentDefinitionCodec.encode(x));
}
}
exports.ArgumentDefinitionCodec = ArgumentDefinitionCodec;