encodeRequest static method

Uint8List encodeRequest({
  1. required String operation,
  2. required PeerId ownerPeerId,
  3. String? path,
  4. Map<String, String>? headers,
  5. Uint8List? body,
  6. String? title,
  7. String? description,
  8. String? entryType,
  9. int? sequenceNumber,
  10. int? fromSequence,
  11. int? toSequence,
  12. int? limit,
  13. bool collaborative = false,
})

Encode feed request

Implementation

static Uint8List encodeRequest({
  required String operation,
  required PeerId ownerPeerId,
  String? path,
  Map<String, String>? headers,
  Uint8List? body,
  String? title,
  String? description,
  String? entryType,
  int? sequenceNumber,
  int? fromSequence,
  int? toSequence,
  int? limit,
  bool collaborative = false,
}) {
  final data = <String, dynamic>{
    'operation': operation,
    'ownerPeerId': ownerPeerId.toString(),
  };

  if (path != null) data['path'] = path;
  if (headers != null && headers.isNotEmpty) data['headers'] = headers;
  if (body != null) data['body'] = base64Encode(body);
  if (title != null) data['title'] = title;
  if (description != null) data['description'] = description;
  if (entryType != null) data['entryType'] = entryType;
  if (sequenceNumber != null) data['sequenceNumber'] = sequenceNumber;
  if (fromSequence != null) data['fromSequence'] = fromSequence;
  if (toSequence != null) data['toSequence'] = toSequence;
  if (limit != null) data['limit'] = limit;
  if (collaborative) data['collaborative'] = true;

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