aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakubtomsu <66876057+jakubtomsu@users.noreply.github.com>2024-09-04 11:08:45 +0200
committerjakubtomsu <66876057+jakubtomsu@users.noreply.github.com>2024-09-04 11:08:45 +0200
commit7487d507be57a467e48e8e3464bae4b579086967 (patch)
tree00027c1173eec53eb4575e71474b911780f17a93
parentc6b551d2c3b104b3bb7e81fdec42885685ad7754 (diff)
unmarshal bitset ints like cbor does
-rw-r--r--core/encoding/json/unmarshal.odin25
1 files changed, 24 insertions, 1 deletions
diff --git a/core/encoding/json/unmarshal.odin b/core/encoding/json/unmarshal.odin
index 127bce650..738e20c68 100644
--- a/core/encoding/json/unmarshal.odin
+++ b/core/encoding/json/unmarshal.odin
@@ -116,7 +116,30 @@ assign_int :: proc(val: any, i: $T) -> bool {
case int: dst = int (i)
case uint: dst = uint (i)
case uintptr: dst = uintptr(i)
- case: return false
+ case:
+ 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)
+ switch ti.size * 8 {
+ case 0: // no-op.
+ case 8:
+ x := (^u8)(v.data)
+ x^ = u8(i)
+ case 16:
+ x := (^u16)(v.data)
+ x^ = do_byte_swap ? intrinsics.byte_swap(u16(i)) : u16(i)
+ case 32:
+ x := (^u32)(v.data)
+ x^ = do_byte_swap ? intrinsics.byte_swap(u32(i)) : u32(i)
+ case 64:
+ x := (^u64)(v.data)
+ x^ = do_byte_swap ? intrinsics.byte_swap(u64(i)) : u64(i)
+ case:
+ panic("unknown bit_size size")
+ }
+ return true
+ }
+ return false
}
return true
}