1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

json2: small refactor after #16896 (#16911)

This commit is contained in:
Hitalo Souza 2023-01-10 06:08:11 -03:00 committed by GitHub
parent 8a986b994e
commit cf95d77584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,8 +130,7 @@ fn (e &Encoder) encode_value_with_level[T](val T, level int, mut wr io.Writer) !
e.encode_any(val, level, mut wr)!
} $else $if T is []Any {
e.encode_any(val, level, mut wr)!
} $else $if T is Null || T is bool || T is f32 || T is f64 || T is i8 || T is i16 || T is int
|| T is i64 || T is u8 || T is u16 || T is u32 || T is u64 {
} $else $if T in [Null, bool, $Float, $Int] {
e.encode_any(val, level, mut wr)!
} $else $if T is Encodable {
wr.write(val.json_str().bytes())!
@ -248,9 +247,7 @@ fn (e &Encoder) encode_struct[U](val U, level int, mut wr io.Writer) ! {
} $else $if field.typ is time.Time {
parsed_time := val.$(field.name) as time.Time
e.encode_string(parsed_time.format_rfc3339(), mut wr)!
} $else $if field.typ is bool || field.typ is f32 || field.typ is f64 || field.typ is i8
|| field.typ is i16 || field.typ is int || field.typ is i64 || field.typ is u8
|| field.typ is u16 || field.typ is u32 || field.typ is u64 {
} $else $if field.typ in [bool, $Float, $Int] {
wr.write(value.str().bytes())!
} $else $if field.is_array {
e.encode_array(value, level + 1, mut wr)!