xiot-core-spec-ts
Version:
XIOT Specification Codec
51 lines (50 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SomewhereCodec = void 0;
const Somewhere_1 = require("../../typedef/somewhere/Somewhere");
const Where_1 = require("../../typedef/somewhere/Where");
class SomewhereCodec {
static decodeArray(list) {
const array = [];
if (list != null) {
for (const o of list) {
array.push(SomewhereCodec.decodeObject(o));
}
}
return array;
}
static decodeObject(o) {
const somewhere = new Somewhere_1.Somewhere();
if (o.where !== undefined) {
somewhere.where = (0, Where_1.WhereFromString)(o.where);
}
if (o.spaceId !== undefined) {
somewhere.spaceId = o.spaceId;
}
if (o.index !== 0) {
somewhere.index = o.index;
}
return somewhere;
}
static encodeObject(s) {
const o = {};
if (s.spaceId != null) {
o.spaceId = s.spaceId;
}
if (s.where != Where_1.Where.UNKNOWN) {
o.where = s.where.toString();
}
if (s.index !== 0) {
o.index = s.index;
}
return o;
}
static encodeArray(array) {
return array != null
? array.map(s => {
return SomewhereCodec.encodeObject(s);
})
: [];
}
}
exports.SomewhereCodec = SomewhereCodec;