"use strict";(self.webpackChunkPrivateMaterials=self.webpackChunkPrivateMaterials||[]).push([["509"],{5276(e,t,r){r.d(t,{EventStreamSerde:()=>s});var i=r(5742),a=r(2987);class s{marshaller;serializer;deserializer;serdeContext;defaultContentType;constructor({marshaller:e,serializer:t,deserializer:r,serdeContext:i,defaultContentType:a}){this.marshaller=e,this.serializer=t,this.deserializer=r,this.serdeContext=i,this.defaultContentType=a}async serializeEventStream({eventStream:e,requestSchema:t,initialRequest:r}){let i=this.marshaller,a=t.getEventStreamMember(),s=t.getMemberSchema(a),n=this.serializer,l=this.defaultContentType,o=Symbol("initialRequestMarker"),m={async *[Symbol.asyncIterator](){if(r){n.write(t,r);let e=n.flush();yield{[o]:!0,headers:{":event-type":{type:"string",value:"initial-request"},":message-type":{type:"string",value:"event"},":content-type":{type:"string",value:l}},body:e}}for await(let t of e)yield t}};return i.serialize(m,e=>{if(e[o])return{headers:e.headers,body:e.body};let t="";for(let r in e)if("__type"!==r){t=r;break}let{additionalHeaders:r,body:i,eventType:a,explicitPayloadContentType:n}=this.writeEventBody(t,s,e);return{headers:{":event-type":{type:"string",value:a},":message-type":{type:"string",value:"event"},":content-type":{type:"string",value:n??l},...r},body:i}})}async deserializeEventStream({response:e,responseSchema:t,initialResponseContainer:r}){let a=this.marshaller,s=t.getEventStreamMember(),n=t.getMemberSchema(s).getMemberSchemas(),l=Symbol("initialResponseMarker"),o=a.deserialize(e.body,async e=>{let r="";for(let t in e)if("__type"!==t){r=t;break}let a=e[r].body;if("initial-response"===r){let e=await this.deserializer.read(t,a);return delete e[s],{[l]:!0,...e}}if(!(r in n))return{$unknown:e};{let t=n[r];if(t.isStructSchema()){let s={},n=!1;for(let[l,o]of t.structIterator()){let{eventHeader:t,eventPayload:m}=o.getMergedTraits();if(n=n||!!(t||m),m)o.isBlobSchema()?s[l]=a:o.isStringSchema()?s[l]=(this.serdeContext?.utf8Encoder??i.P)(a):o.isStructSchema()&&(s[l]=await this.deserializer.read(o,a));else if(t){let t=e[r].headers[l]?.value;null!=t&&(o.isNumericSchema()?t&&"object"==typeof t&&"bytes"in t?s[l]=BigInt(t.toString()):s[l]=Number(t):s[l]=t)}}if(n)return{[r]:s};if(0===a.byteLength)return{[r]:{}}}return{[r]:await this.deserializer.read(t,a)}}}),m=o[Symbol.asyncIterator](),u=await m.next();if(u.done)return o;if(u.value?.[l]){if(!t)throw Error("@smithy::core/protocols - initial-response event encountered in event stream but no response schema given.");for(let e in u.value)r[e]=u.value[e]}return{async *[Symbol.asyncIterator](){for(u?.value?.[l]||(yield u.value);;){let{done:e,value:t}=await m.next();if(e)break;yield t}}}}writeEventBody(e,t,r){let i,s=this.serializer,n=e,l=null,o=t.getSchema()[4].includes(e),m={};if(o){let a=t.getMemberSchema(e);if(a.isStructSchema()){for(let[t,i]of a.structIterator()){let{eventHeader:a,eventPayload:s}=i.getMergedTraits();if(s)l=t;else if(a){let a=r[e][t],s="binary";i.isNumericSchema()?s=-0x80000000<=a&&a<=0x80000000-1?"integer":"long":i.isTimestampSchema()?s="timestamp":i.isStringSchema()?s="string":i.isBooleanSchema()&&(s="boolean"),null!=a&&(m[t]={type:s,value:a},delete r[e][t])}}if(null!==l){let t=a.getMemberSchema(l);t.isBlobSchema()?i="application/octet-stream":t.isStringSchema()&&(i="text/plain"),s.write(t,r[e][l])}else s.write(a,r[e])}else if(a.isUnitSchema())s.write(a,{});else throw Error("@smithy/core/event-streams - non-struct member not supported in event stream union.")}else{let[t,i]=r[e];n=t,s.write(15,i)}let u=s.flush()??new Uint8Array;return{body:"string"==typeof u?(this.serdeContext?.utf8Decoder??a.a)(u):u,eventType:n,explicitPayloadContentType:i,additionalHeaders:m}}}}}]);