xiot-core-spec-ts
Version:
XIOT Specification Codec
63 lines (62 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OwnershipCodec = void 0;
const Ownership_1 = require("../../typedef/ownership/Ownership");
class OwnershipCodec {
static decode(o) {
const ownership = new Ownership_1.Ownership();
ownership.appId = o.appId;
ownership.ownerId = o.ownerId;
ownership.did = o.did;
ownership.token = o.token;
ownership.cloudId = o.cloudId;
ownership.rootId = o.rootId;
if (o.createAt !== undefined) {
ownership.createAt = new Date(o.createAt);
}
if (o.updateAt !== undefined) {
ownership.updateAt = new Date(o.updateAt);
}
return ownership;
}
static encode(x) {
const object = {
appId: x.appId,
ownerId: x.ownerId,
did: x.did,
token: x.token
};
if (x.cloudId != null) {
object.cloudId = x.cloudId;
}
if (x.rootId != null) {
object.rootId = x.rootId;
}
if (x.createAt != null) {
object.createAt = x.createAt.getTime();
}
if (x.updateAt != null) {
object.updateAt = x.updateAt.getTime();
}
return object;
}
static decodeArray(arr) {
const list = [];
if (arr === null || arr === void 0 ? void 0 : arr.length) {
for (const o of arr) {
list.push(this.decode(o));
}
}
return list;
}
static encodeArray(Ownerships) {
const arr = [];
if (Ownerships === null || Ownerships === void 0 ? void 0 : Ownerships.length) {
for (const p of Ownerships) {
arr.push(this.encode(p));
}
}
return arr;
}
}
exports.OwnershipCodec = OwnershipCodec;