encodeRequest static method

Uint8List encodeRequest({
  1. required String operation,
  2. required PeerId ownerPeerId,
  3. String? path,
  4. String? key,
  5. Map<String, String>? headers,
  6. Uint8List? body,
  7. String? name,
  8. Map<String, dynamic>? filter,
  9. String? sortField,
  10. bool? sortAsc,
  11. int? limit,
  12. int? offset,
  13. String? cursor,
  14. bool wantTotal = false,
  15. String? visibility,
  16. String? accessAction,
  17. String? readerPeerId,
})

Encode collection request

Implementation

static Uint8List encodeRequest({
  required String operation,
  required PeerId ownerPeerId,
  String? path,
  String? key,
  Map<String, String>? headers,
  Uint8List? body,
  String? name,
  Map<String, dynamic>? filter,
  String? sortField,
  bool? sortAsc,
  int? limit,
  int? offset,
  String? cursor,
  bool wantTotal = false,
  String? visibility,
  String? accessAction,
  String? readerPeerId,
}) {
  final data = <String, dynamic>{
    'operation': operation,
    'ownerPeerId': ownerPeerId.toString(),
  };

  if (path != null) data['path'] = path;
  if (key != null) data['key'] = key;
  if (headers != null && headers.isNotEmpty) data['headers'] = headers;
  if (body != null) data['body'] = base64Encode(body);
  if (name != null) data['name'] = name;
  if (filter != null) data['filter'] = filter;
  if (sortField != null) data['sortField'] = sortField;
  if (sortAsc != null) data['sortAsc'] = sortAsc;
  if (limit != null) data['limit'] = limit;
  if (offset != null) data['offset'] = offset;
  if (cursor != null) data['cursor'] = cursor;
  if (wantTotal) data['wantTotal'] = true;
  if (visibility != null) data['visibility'] = visibility;
  if (accessAction != null) data['accessAction'] = accessAction;
  if (readerPeerId != null) data['readerPeerId'] = readerPeerId;

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