IndexAllocatorOwnershipImage.fromJson constructor
Decodes allocator ownership.
Implementation
factory IndexAllocatorOwnershipImage.fromJson(Map<String, Object?> json) {
_validateHeader(json, kind, version);
final capacity = _positiveInt(json, 'capacity');
final encoded = json['allocatedIndices'];
if (encoded is! List<Object?> || encoded.any((index) => index is! int)) {
throw const FormatException('allocatedIndices must be an integer list.');
}
final indices = encoded.cast<int>();
if (indices.toSet().length != indices.length) {
throw const FormatException('allocatedIndices must not contain repeats.');
}
return IndexAllocatorOwnershipImage(
capacity: capacity,
allocatedIndices: indices,
);
}