mapRecordToJson function

Map<String, dynamic>? mapRecordToJson(
  1. Record? record
)

Maps any Records known to this Protocol to their JSON representation

Throws in case the record type is not known.

This method will return null (only) for null inputs.

Implementation

Map<String, dynamic>? mapRecordToJson(Record? record) {
  if (record == null) {
    return null;
  }
  if (record is ({
    List<
        ({
          String countryCode,
          String downloadLink,
          String languageCode
        })> languages,
    DateTime updatedAt
  })) {
    return {
      "n": {
        "languages": record.languages,
        "updatedAt": record.updatedAt,
      },
    };
  }
  if (record is ({
    String countryCode,
    String downloadLink,
    String languageCode
  })) {
    return {
      "n": {
        "countryCode": record.countryCode,
        "downloadLink": record.downloadLink,
        "languageCode": record.languageCode,
      },
    };
  }
  if (record is ({String sha, DateTime updatedDate})) {
    return {
      "n": {
        "sha": record.sha,
        "updatedDate": record.updatedDate,
      },
    };
  }
  if (record is ({String sha, DateTime updatedDate})) {
    return {
      "n": {
        "sha": record.sha,
        "updatedDate": record.updatedDate,
      },
    };
  }
  throw Exception('Unsupported record type ${record.runtimeType}');
}