I am using 'packed struct(u32) ’ to represent the registers on the A64 SoC. I got some debug output working at last over serial cable and now I want to use reflection to debug the register values.
I can treat them as u32 and can already dump the hex values but I was trying to be clever with the bit fields, and my packed structs are broken down into a series of u1, bool, u3, enum(u3), u8, u24 etc etc.
So I can check for ‘bool’ field type, use @field to access the value, and output “true” or “false” per bit flag next to the field name, nice! thank-you Zig
For the rest it is a bit messy, I have a huge if(typ == u1 or typ == u2 … or typ == u32).
Is there a way to simplify the if clause to something like @isNumeric(typ)?
Similarly, is there a way to ask @isEnum(typ) (I dont want to add if clauses for every enum I defined, I will just @intFromEnum them all, or maybe I will at a later date assuming I can get back to the Enum field name)
I tried to see how println format is working, but I am so lost browsing the code & docs that I couldnt even locate the format specifiers. Although maybe I imagined a struct formatter, or possibly it is from Go.
I only got this far because I found a Test Case for packed struct. I have no idea if accessing the fields via typInfo.@“struct”.fields is even correct? Having a string involved feels a bit hacky, but it works