encodeResponse static method

Uint8List encodeResponse({
  1. required int status,
  2. Map<String, dynamic>? headers,
  3. Uint8List? body,
})

Encode document response

Implementation

static Uint8List encodeResponse({
  required int status,
  Map<String, dynamic>? headers,
  Uint8List? body,
}) {
  final data = <String, dynamic>{
    'status': status,
  };

  if (headers != null && headers.isNotEmpty) {
    data['headers'] = headers;
  }

  if (body != null) {
    final base64Body = base64Encode(body);
    data['body'] = base64Body;
  }

  final json = jsonEncode(data);
  return Uint8List.fromList(utf8.encode(json));
}