aboutsummaryrefslogtreecommitdiff
path: root/core/encoding/json
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2025-03-22 00:20:00 +0100
committerLaytan Laats <laytanlaats@hotmail.com>2025-03-22 00:20:00 +0100
commite4bc9677af62c74bb23f4c00d82d2a685ce64e50 (patch)
tree6a1ef937dc81260b27edbfcd07637bcac029ac17 /core/encoding/json
parentcf0f73e0cfee96e54e6347d572a39b2611b523e0 (diff)
fix unmarshalling bit sets in json
Fixes #4761
Diffstat (limited to 'core/encoding/json')
-rw-r--r--core/encoding/json/unmarshal.odin20
1 files changed, 18 insertions, 2 deletions
diff --git a/core/encoding/json/unmarshal.odin b/core/encoding/json/unmarshal.odin
index 57371e360..151bd69c3 100644
--- a/core/encoding/json/unmarshal.odin
+++ b/core/encoding/json/unmarshal.odin
@@ -117,9 +117,25 @@ assign_int :: proc(val: any, i: $T) -> bool {
case uint: dst = uint (i)
case uintptr: dst = uintptr(i)
case:
+ is_bit_set_different_endian_to_platform :: proc(ti: ^runtime.Type_Info) -> bool {
+ if ti == nil {
+ return false
+ }
+ t := runtime.type_info_base(ti)
+ #partial switch info in t.variant {
+ case runtime.Type_Info_Integer:
+ switch info.endianness {
+ case .Platform: return false
+ case .Little: return ODIN_ENDIAN != .Little
+ case .Big: return ODIN_ENDIAN != .Big
+ }
+ }
+ return false
+ }
+
ti := type_info_of(v.id)
- if _, ok := ti.variant.(runtime.Type_Info_Bit_Set); ok {
- do_byte_swap := !reflect.bit_set_is_big_endian(v)
+ if info, ok := ti.variant.(runtime.Type_Info_Bit_Set); ok {
+ do_byte_swap := is_bit_set_different_endian_to_platform(info.underlying)
switch ti.size * 8 {
case 0: // no-op.
case 8: