parse static method

GameStorageQuotas parse(
  1. Object? json
)

Implementation

static GameStorageQuotas parse(Object? json) {
  if (json is! Map) return defaults;
  try {
    final v = _bytes(json['valueMaxBytes'], 1024, 1024 * 1024);
    final ns = _bytes(json['namespaceMaxBytes'], 4 * 1024, 16 * 1024 * 1024);
    if (v == null || ns == null) {
      // Missing keys take defaults; malformed/out-of-range poisons whole.
      if (_isMalformed(json['valueMaxBytes'], 1024, 1024 * 1024) ||
          _isMalformed(
              json['namespaceMaxBytes'], 4 * 1024, 16 * 1024 * 1024)) {
        return defaults;
      }
      return GameStorageQuotas(
        valueMaxBytes: v ?? defaults.valueMaxBytes,
        namespaceMaxBytes: ns ?? defaults.namespaceMaxBytes,
      );
    }
    return GameStorageQuotas(valueMaxBytes: v, namespaceMaxBytes: ns);
  } catch (_) {
    return defaults;
  }
}