@@ -108,10 +108,17 @@ static void generateMetadataDeserializer(GenerationContext context, SymbolRefere
108
108
writer .write ("" );
109
109
}
110
110
111
+ /**
112
+ * Writes a response body stream collector. This function converts the low-level response body stream to
113
+ * Uint8Array binary data.
114
+ *
115
+ * @param context The generation context.
116
+ */
111
117
static void generateCollectBody (GenerationContext context ) {
112
118
TypeScriptWriter writer = context .getWriter ();
113
119
114
120
writer .addImport ("SerdeContext" , "__SerdeContext" , "@aws-sdk/types" );
121
+ writer .write ("// Collect low-level response body stream to Uint8Array." );
115
122
writer .openBlock ("const collectBody = (streamBody: any, context: __SerdeContext): Promise<Uint8Array> => {" ,
116
123
"};" , () -> {
117
124
writer .write ("return context.streamCollector(streamBody) || new Uint8Array();" );
@@ -120,10 +127,17 @@ static void generateCollectBody(GenerationContext context) {
120
127
writer .write ("" );
121
128
}
122
129
130
+ /**
131
+ * Writes a function converting the low-level response body stream to utf-8 encoded string. It depends on
132
+ * response body stream collector{@link #generateCollectBody(GenerationContext)}.
133
+ *
134
+ * @param context The generation context
135
+ */
123
136
static void generateCollectBodyString (GenerationContext context ) {
124
137
TypeScriptWriter writer = context .getWriter ();
125
138
126
139
writer .addImport ("SerdeContext" , "__SerdeContext" , "@aws-sdk/types" );
140
+ writer .write ("// Encode Uint8Array data into string with utf-8." );
127
141
writer .openBlock ("const collectBodyString = (streamBody: any, context: __SerdeContext): Promise<string> => {" ,
128
142
"};" , () -> {
129
143
writer .write ("return collectBody(streamBody, context).then(body => context.utf8Encoder(body));" );
@@ -167,11 +181,12 @@ static Set<StructureShape> generateErrorDispatcher(
167
181
// Prepare error response for parsing error code. If error code needs to be parsed from response body
168
182
// then we collect body and parse it to JS object, otherwise leave the response body as is.
169
183
writer .openBlock (
170
- "const $L: any = {" , "};" , shouldParseErrorBody ? "parsedOutput" : "errorOutput" , () -> {
171
- writer .write ("...output," );
172
- writer .write ("body: $L," ,
173
- shouldParseErrorBody ? "await parseBody(output.body, context)" : "output.body" );
174
- });
184
+ "const $L: any = {" , "};" , shouldParseErrorBody ? "parsedOutput" : "errorOutput" ,
185
+ () -> {
186
+ writer .write ("...output," );
187
+ writer .write ("body: $L," ,
188
+ shouldParseErrorBody ? "await parseBody(output.body, context)" : "output.body" );
189
+ });
175
190
176
191
// Error responses must be at least SmithyException and MetadataBearer implementations.
177
192
writer .addImport ("SmithyException" , "__SmithyException" ,
0 commit comments