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