x.json2: add u64 (#9457)
							parent
							
								
									a2ef9967fe
								
							
						
					
					
						commit
						1bf7d968f9
					
				|  | @ -4,7 +4,7 @@ | |||
| module json2 | ||||
| 
 | ||||
| // `Any` is a sum type that lists the possible types to be decoded and used.
 | ||||
| pub type Any = Null | []Any | bool | f32 | f64 | i64 | int | map[string]Any | string | ||||
| pub type Any = Null | []Any | bool | f32 | f64 | i64 | u64 | int | map[string]Any | string | ||||
| 
 | ||||
| // `Null` struct is a simple representation of the `null` value in JSON.
 | ||||
| pub struct Null { | ||||
|  |  | |||
|  | @ -70,7 +70,7 @@ pub fn (f Any) json_str() string { | |||
| 		int { | ||||
| 			return f.str() | ||||
| 		} | ||||
| 		i64 { | ||||
| 		u64, i64 { | ||||
| 			return f.str() | ||||
| 		} | ||||
| 		f32 { | ||||
|  |  | |||
|  | @ -71,6 +71,15 @@ pub fn (f Any) i64() i64 { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| // u64 uses `Any` as a 64-bit unsigned integer.
 | ||||
| pub fn (f Any) u64() u64 { | ||||
| 	match f { | ||||
| 		u64 { return f } | ||||
| 		int, i64, f32, f64, bool { return u64(f) } | ||||
| 		else { return 0 } | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // f32 uses `Any` as a 32-bit float.
 | ||||
| pub fn (f Any) f32() f32 { | ||||
| 	match f { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue