MemoryType.fromJson constructor

MemoryType.fromJson(
  1. Object? json_
)

Returns a new instance from a JSON value. May throw if the value does not have the expected structure.

Implementation

factory MemoryType.fromJson(Object? json_) {
  final json = json_ is Map
      ? _spec.fields.map((f) => json_[f.label]).toList(growable: false)
      : json_;
  return switch (json) {
    [final memory64, final shared, final minimum, final maximum] ||
    (final memory64, final shared, final minimum, final maximum) =>
      MemoryType(
        memory64: memory64! as bool,
        shared: shared! as bool,
        minimum: bigIntFromJson(minimum),
        maximum:
            Option.fromJson(maximum, (some) => bigIntFromJson(some)).value,
      ),
    _ => throw Exception('Invalid JSON $json_')
  };
}