UNPKG

xiot-core-spec-ts

Version:
42 lines (41 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventReceiverCodec = void 0; const EventReceiverType_1 = require("../../../typedef/app/event/EventReceiverType"); const EventReceiverEventbusImplCodec_1 = require("./impl/EventReceiverEventbusImplCodec"); const EventReceiverHttpImplCodec_1 = require("./impl/EventReceiverHttpImplCodec"); const EventReceiverKafkaImplCodec_1 = require("./impl/EventReceiverKafkaImplCodec"); const EventReceiverEventbusImpl_1 = require("../../../typedef/app/event/impl/EventReceiverEventbusImpl"); const EventReceiverHttpImpl_1 = require("../../../typedef/app/event/impl/EventReceiverHttpImpl"); const EventReceiverKafkaImpl_1 = require("../../../typedef/app/event/impl/EventReceiverKafkaImpl"); class EventReceiverCodec { static decode(o) { const type = (0, EventReceiverType_1.EventReceiverTypeFromString)(o.type); switch (type) { case EventReceiverType_1.EventReceiverType.EVENTBUS: return EventReceiverEventbusImplCodec_1.EventReceiverEventbusImplCodec.decode(o['eventbus']); case EventReceiverType_1.EventReceiverType.HTTP: return EventReceiverHttpImplCodec_1.EventReceiverHttpImplCodec.decode(o['http']); case EventReceiverType_1.EventReceiverType.KAFKA: return EventReceiverKafkaImplCodec_1.EventReceiverKafkaImplCodec.decode(o['kafka']); default: throw new Error('EventReceiver Invalid: ' + o); } } static encode(x) { const o = { type: x.type.toString() }; if (x instanceof EventReceiverEventbusImpl_1.EventReceiverEventbusImpl) { o.eventbus = EventReceiverEventbusImplCodec_1.EventReceiverEventbusImplCodec.encode(x); } else if (x instanceof EventReceiverHttpImpl_1.EventReceiverHttpImpl) { o.http = EventReceiverHttpImplCodec_1.EventReceiverHttpImplCodec.encode(x); } else if (x instanceof EventReceiverKafkaImpl_1.EventReceiverKafkaImpl) { o.kafka = EventReceiverKafkaImplCodec_1.EventReceiverKafkaImplCodec.encode(x); } return o; } } exports.EventReceiverCodec = EventReceiverCodec;