66
77import 'dart:convert' ;
88import 'dart:io' ;
9- import 'dart:typed_data' ;
109
1110import 'package:http_parser/http_parser.dart' ;
1211import 'package:json_schema/json_schema.dart' ;
@@ -169,19 +168,19 @@ class ContentSerdes {
169168 final mimeType = parsedMediaType.mimeType;
170169 final parameters = parsedMediaType.parameters;
171170
172- ByteBuffer bytes;
171+ List < int > bytes;
173172 final codec = _getCodecFromMediaType (mimeType);
173+
174174 if (codec != null ) {
175175 bytes = codec.valueToBytes (value, dataSchema, parameters);
176176 } else {
177177 // Media Type is unsupported. Convert the String representation to bytes
178178 // instead.
179179 // TODO(JKRhb): Could be moved to a dedicated Value class method.
180- bytes = utf8.encoder.convert (value.toString ()).buffer ;
180+ bytes = utf8.encoder.convert (value.toString ());
181181 }
182182
183- final byteList = bytes.asUint8List ().toList (growable: false );
184- return Content (resolvedMediaType, Stream .value (byteList));
183+ return Content (resolvedMediaType, Stream .value (bytes));
185184 }
186185
187186 /// Converts a [Content] object to a typed [Object] .
@@ -197,10 +196,10 @@ class ContentSerdes {
197196 final mimeType = parsedMediaType.mimeType;
198197 final parameters = parsedMediaType.parameters;
199198
200- final bytes = await content.byteBuffer ;
199+ final bytes = await content.toByteList () ;
201200
202201 // TODO: Should null be returned in this case?
203- if (bytes.lengthInBytes == 0 ) {
202+ if (bytes.isEmpty ) {
204203 return null ;
205204 }
206205
@@ -211,7 +210,7 @@ class ContentSerdes {
211210 return value;
212211 } else {
213212 // TODO(JKRhb): Should unsupported data be returned as a String?
214- return utf8.decode (bytes.asUint8List ());
213+ return utf8.decode (bytes.toList ());
215214 }
216215 }
217216}
0 commit comments