diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index 9814f3139..3dde3bffc 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -121,14 +121,18 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: } else { switch i in a { case u8, u16, u32, u64: - s = strconv.append_bits(buf[:], u, 8, info.signed, 8*ti.size, "0123456789abcdef", { .Prefix }) + s = strconv.append_bits(buf[:], u, 16, info.signed, 8*ti.size, "0123456789abcdef", { .Prefix }) case: - s = strconv.append_bits(buf[:], u, 8, info.signed, 8*ti.size, "0123456789", nil) + s = strconv.append_bits(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil) } } } else { - s = strconv.append_bits_128(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil) + when ODIN_ALLOW_128_BIT { + s = strconv.append_bits_128(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil) + } else { + s = strconv.append_bits(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil) + } } io.write_string(w, s) or_return @@ -289,8 +293,14 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: opt_write_key(w, opt, name) or_return case runtime.Type_Info_Integer: buf: [40]byte - u := cast_any_int_to_u128(ka) - name = strconv.append_bits_128(buf[:], u, 10, info.signed, 8*kti.size, "0123456789", nil) + when ODIN_ALLOW_128_BIT { + u := cast_any_int_to_u128(ka) + name = strconv.append_bits_128(buf[:], u, 10, info.signed, 8*kti.size, "0123456789", nil) + } else { + u := cast_any_int_to_u64(ka) + name = strconv.append_bits(buf[:], u, 10, info.signed, 8*kti.size, "0123456789", nil) + + } opt_write_key(w, opt, name) or_return case: return .Unsupported_Type @@ -693,7 +703,6 @@ when ODIN_ALLOW_128_BIT { case i16: u = u64(i) case i32: u = u64(i) case i64: u = u64(i) - case i128: u = u64(i) case int: u = u64(i) case u8: u = u64(i) case u16: u = u64(i) diff --git a/core/encoding/json/unmarshal.odin b/core/encoding/json/unmarshal.odin index 3fd99b57b..5685c8506 100644 --- a/core/encoding/json/unmarshal.odin +++ b/core/encoding/json/unmarshal.odin @@ -218,7 +218,11 @@ unmarshal_string_token :: proc(p: ^Parser, val: any, str: string, ti: ^reflect.T return true, nil case reflect.Type_Info_Integer: - i, pok := strconv.parse_i128(str) + when ODIN_ALLOW_128_BIT { + i, pok := strconv.parse_i128(str) + } else { + i, pok := strconv.parse_i64(str) + } if !pok { return false, nil } @@ -301,7 +305,11 @@ unmarshal_value :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) { case .Integer: advance_token(p) - i, _ := strconv.parse_i128(token.text) + when ODIN_ALLOW_128_BIT { + i, _ := strconv.parse_i128(token.text) + } else { + i, _ := strconv.parse_i64(token.text) + } if assign_int(v, i) { return } @@ -561,7 +569,11 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm key_ptr = &key_cstr } case runtime.Type_Info_Integer: - i, ok := strconv.parse_i128(key) + when ODIN_ALLOW_128_BIT { + i, ok := strconv.parse_i128(key) + } else { + i, ok := strconv.parse_i64(key) + } if !ok { return UNSUPPORTED_TYPE } key_ptr = rawptr(&i) case: return UNSUPPORTED_TYPE