kaitai_struct_compiler icon indicating copy to clipboard operation
kaitai_struct_compiler copied to clipboard

Golang: fix enum type for large values

Open lucebac opened this issue 3 years ago • 6 comments

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.

lucebac avatar Jun 21 '22 17:06 lucebac

+1

puhitaku avatar Jun 23 '22 09:06 puhitaku

@lucebac @puhitaku Apologies for very late response.

  1. Do we need a new test to cover these among others already available in tests repo?
  2. Do we need a special golang build to test this? (rather than the one we use in CI)

GreyCat avatar Jul 21 '23 11:07 GreyCat

  1. 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
  2. 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

lucebac avatar Jul 22 '23 23:07 lucebac

  1. 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.

GreyCat avatar Jul 24 '23 09:07 GreyCat

Yes and no. I want to be able to export the enum members in generated code so I believe the enum is correct

lucebac avatar Jul 25 '23 17:07 lucebac

Hi @GreyCat have found the time to decide on whether or not this change will be accepted?

lucebac avatar Nov 01 '23 23:11 lucebac