decodeResponse static method
Decode collection response
Implementation
static CollectionFrameResponse decodeResponse(Uint8List bytes) {
final json = utf8.decode(bytes);
final data = jsonDecode(json) as Map<String, dynamic>;
final headers = data['headers'] != null
? Map<String, dynamic>.from(data['headers'] as Map)
: <String, dynamic>{};
// go-ricochet sends JSON payloads (an item's content, a QUERY page) as
// raw JSON in `data`, not base64 in `body`. Older servers use `body`.
// Both arrive here as the payload's bytes.
final Uint8List? body;
if (data['data'] != null) {
body = Uint8List.fromList(utf8.encode(jsonEncode(data['data'])));
} else if (data['body'] != null) {
body = base64Decode(data['body'] as String);
} else {
body = null;
}
return CollectionFrameResponse(
status: data['status'] as int,
headers: headers,
body: body,
);
}