fromJson static method

ChunkedFileManifest? fromJson(
  1. dynamic value
)

Returns a new ChunkedFileManifest instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static ChunkedFileManifest? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'manifestId'), 'Required key "ChunkedFileManifest[manifestId]" is missing from JSON.');
      assert(json[r'manifestId'] != null, 'Required key "ChunkedFileManifest[manifestId]" has a null value in JSON.');
      assert(json.containsKey(r'fileId'), 'Required key "ChunkedFileManifest[fileId]" is missing from JSON.');
      assert(json[r'fileId'] != null, 'Required key "ChunkedFileManifest[fileId]" has a null value in JSON.');
      assert(json.containsKey(r'fileName'), 'Required key "ChunkedFileManifest[fileName]" is missing from JSON.');
      assert(json[r'fileName'] != null, 'Required key "ChunkedFileManifest[fileName]" has a null value in JSON.');
      assert(json.containsKey(r'version'), 'Required key "ChunkedFileManifest[version]" is missing from JSON.');
      assert(json[r'version'] != null, 'Required key "ChunkedFileManifest[version]" has a null value in JSON.');
      assert(json.containsKey(r'totalSize'), 'Required key "ChunkedFileManifest[totalSize]" is missing from JSON.');
      assert(json[r'totalSize'] != null, 'Required key "ChunkedFileManifest[totalSize]" has a null value in JSON.');
      assert(json.containsKey(r'blockCount'), 'Required key "ChunkedFileManifest[blockCount]" is missing from JSON.');
      assert(json[r'blockCount'] != null, 'Required key "ChunkedFileManifest[blockCount]" has a null value in JSON.');
      return true;
    }());

    return ChunkedFileManifest(
      manifestId: mapValueOfType<String>(json, r'manifestId')!,
      fileId: mapValueOfType<String>(json, r'fileId')!,
      fileName: mapValueOfType<String>(json, r'fileName')!,
      version: mapValueOfType<int>(json, r'version')!,
      totalSize: mapValueOfType<int>(json, r'totalSize')!,
      blockCount: mapValueOfType<int>(json, r'blockCount')!,
      chunkingAlgorithm: mapValueOfType<String>(json, r'chunkingAlgorithm'),
      fileChecksum: mapValueOfType<String>(json, r'fileChecksum'),
      blocks: Map.listFromJson(json[r'blocks']),
    );
  }
  return null;
}