decodeRequest static method

CollectionRequest decodeRequest(
  1. Uint8List bytes
)

Decode collection request

Implementation

static CollectionRequest decodeRequest(Uint8List bytes) {
  final json = utf8.decode(bytes);
  final data = jsonDecode(json) as Map<String, dynamic>;

  final headers = data['headers'] != null
      ? Map<String, String>.from(data['headers'] as Map)
      : <String, String>{};

  final body = data['body'] != null
      ? base64Decode(data['body'] as String)
      : null;

  return CollectionRequest(
    operation: data['operation'] as String,
    ownerPeerId: PeerId.fromString(data['ownerPeerId'] as String),
    path: data['path'] as String?,
    key: data['key'] as String?,
    headers: headers,
    body: body,
    name: data['name'] as String?,
    filter: data['filter'] as Map<String, dynamic>?,
    sortField: data['sortField'] as String?,
    sortAsc: data['sortAsc'] as bool?,
    limit: data['limit'] as int?,
    offset: data['offset'] as int?,
  );
}