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