kaitai_struct_compiler
kaitai_struct_compiler copied to clipboard
Golang: fix enum type for large values
When using 32bit Golang, the standard int type only holds 32 bits. This is a problem when the enum keys are larger than Int.MaxValue. This fix should solve the problem for Golang. However, I cannot tell whether this issue also affects other languages which then need a fix as well. Maybe, there is a more thorough solution for this anyway - I'm not at all used to Scala so my fix might be not the ideal way of doing this.
+1
@lucebac @puhitaku Apologies for very late response.
- Do we need a new test to cover these among others already available in tests repo?
- Do we need a special golang build to test this? (rather than the one we use in CI)
- I am not sure. Please see this part of my code where I needed these large enum values for: https://github.com/GDATAAdvancedAnalytics/winreg-tasks/blob/72bc92e0623f9ed3212a04bf81bcce9efc7d7216/kaitai/optional_settings.ksy#L89..L93
- no, Golang natively supports 64 bit integers. My change just makes kaitai use 64bit integers in enums when the values exceed the maximum for 32bit integers. So as long as the fix is in place, everything should be working ootb
- I am not sure. Please see this part of my code where I needed these large enum values for: https://github.com/GDATAAdvancedAnalytics/winreg-tasks/blob/72bc92e0623f9ed3212a04bf81bcce9efc7d7216/kaitai/optional_settings.ksy#L89..L93
Got it, let me try to reproduce it in a test.
In this specific case you seem to be abusing enums for bitmasks. Very likely you'd want to replace that enum with a separate type with bit-sized flags.
Yes and no. I want to be able to export the enum members in generated code so I believe the enum is correct
Hi @GreyCat have found the time to decide on whether or not this change will be accepted?