UNPKG

@softchef/cdk-iot-device-management

Version:

IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.

26 lines (25 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventStreamMarshaller = void 0; const eventstream_marshaller_1 = require("@aws-sdk/eventstream-marshaller"); const eventstream_serde_universal_1 = require("@aws-sdk/eventstream-serde-universal"); const utils_1 = require("./utils"); class EventStreamMarshaller { constructor({ utf8Encoder, utf8Decoder }) { this.eventMarshaller = new eventstream_marshaller_1.EventStreamMarshaller(utf8Encoder, utf8Decoder); this.universalMarshaller = new eventstream_serde_universal_1.EventStreamMarshaller({ utf8Decoder, utf8Encoder, }); } deserialize(body, deserializer) { const bodyIterable = isReadableStream(body) ? utils_1.readableStreamtoIterable(body) : body; return this.universalMarshaller.deserialize(bodyIterable, deserializer); } serialize(input, serializer) { const serialziedIterable = this.universalMarshaller.serialize(input, serializer); return typeof ReadableStream === "function" ? utils_1.iterableToReadableStream(serialziedIterable) : serialziedIterable; } } exports.EventStreamMarshaller = EventStreamMarshaller; const isReadableStream = (body) => typeof ReadableStream === "function" && body instanceof ReadableStream;