fromJson static method

RandomSnapshot fromJson(
  1. Map<String, Object?> json
)

Throws FormatException for a missing/wrong-typed field — same "untrusted input, fail loud rather than silently produce a bogus RNG stream" posture as the rest of this package's persisted state.

Implementation

static RandomSnapshot fromJson(Map<String, Object?> json) {
  final algorithmVersion = json['algorithmVersion'];
  final state = json['state'];
  if (algorithmVersion is! int || state is! int) {
    throw const FormatException(
      'RandomSnapshot.fromJson: algorithmVersion and state must both be int',
    );
  }
  return RandomSnapshot(algorithmVersion: algorithmVersion, state: state);
}