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.

36 lines (35 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventStreamMarshaller = void 0; const eventstream_marshaller_1 = require("@aws-sdk/eventstream-marshaller"); const getChunkedStream_1 = require("./getChunkedStream"); const getUnmarshalledStream_1 = require("./getUnmarshalledStream"); class EventStreamMarshaller { constructor({ utf8Encoder, utf8Decoder }) { this.eventMarshaller = new eventstream_marshaller_1.EventStreamMarshaller(utf8Encoder, utf8Decoder); this.utfEncoder = utf8Encoder; } deserialize(body, deserializer) { const chunkedStream = getChunkedStream_1.getChunkedStream(body); const unmarshalledStream = getUnmarshalledStream_1.getUnmarshalledStream(chunkedStream, { eventMarshaller: this.eventMarshaller, deserializer, toUtf8: this.utfEncoder, }); return unmarshalledStream; } serialize(input, serializer) { const self = this; const serializedIterator = async function* () { for await (const chunk of input) { const payloadBuf = self.eventMarshaller.marshall(serializer(chunk)); yield payloadBuf; } yield new Uint8Array(0); }; return { [Symbol.asyncIterator]: serializedIterator, }; } } exports.EventStreamMarshaller = EventStreamMarshaller;