x.json2: add u64 (#9457)

pull/9468/head
pancake 2021-03-25 16:53:39 +01:00 committed by GitHub
parent a2ef9967fe
commit 1bf7d968f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -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 {

View File

@ -70,7 +70,7 @@ pub fn (f Any) json_str() string {
int {
return f.str()
}
i64 {
u64, i64 {
return f.str()
}
f32 {

View File

@ -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 {