diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-08-30 22:04:10 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-08-30 22:04:10 +0200 |
| commit | db3bcd2cea70955b0e7c1d910ddc66c3843f6eb1 (patch) | |
| tree | 1a48949b68ed88529cf4dabdaa616c02312e7210 | |
| parent | 3072a02d5d48bdfcd7c491f4d35a1de0508be3d1 (diff) | |
Add reflect.bit_fields_zipped
| -rw-r--r-- | core/reflect/reflect.odin | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/reflect/reflect.odin b/core/reflect/reflect.odin index decba00ee..2026ffef9 100644 --- a/core/reflect/reflect.odin +++ b/core/reflect/reflect.odin @@ -1699,3 +1699,26 @@ equal :: proc(a, b: any, including_indirect_array_recursion := false, recursion_ runtime.print_string("\n") return true } + +Bit_Field :: struct { + name: string, + type: ^Type_Info, + size: uintptr, + offset: uintptr, + tag: Struct_Tag, +} + +@(require_results) +bit_fields_zipped :: proc(T: typeid) -> (fields: #soa[]Bit_Field) { + ti := runtime.type_info_base(type_info_of(T)) + if s, ok := ti.variant.(runtime.Type_Info_Bit_Field); ok { + return soa_zip( + name = s.names[:s.field_count], + type = s.types[:s.field_count], + size = s.bit_sizes[:s.field_count], + offset = s.bit_offsets[:s.field_count], + tag = ([^]Struct_Tag)(s.tags)[:s.field_count], + ) + } + return nil +}
\ No newline at end of file |