///|
/// The format number of a file that Mission Control saves: a whole number of 1
/// or more. It is the only field that each format of a file has, so a reader
/// decodes it before the other fields.
///
/// The decoder accepts only a JSON number. A number above 2147483647 becomes
/// 2147483647, because such a format is newer and not damaged.
priv struct SavedFormat {
format : Int32
}
///|
impl @json.FromJson for SavedFormat with fn from_json(json, path) {
if json is Object(fields) &&
fields.get("format") is Some(Number(number, ..)) &&
number > project_largest_int.to_double() &&
number == number.floor() {
return { format: project_largest_int, }
}
let format : Int32 = match json {
Object(fields) =>
match fields.get("format") {
None | Some(Null) => raise path.error("the field \"format\" is missing")
Some(value) => @json.from_json(value, path=path.add_key("format"))
}
_ => raise path.error("expected an object")
}
guard format >= 1 else {
raise path.add_key("format").error("the format \{format} is less than 1")
}
{ format, }
}