valery1707 / kaitai-gradle-plugin

Gradle plugin for Kaitai: declarative language to generate binary data parsers
https://kaitai.io/
MIT License
6 stars 4 forks source link

It doesn't handle unsigned integer properly #17

Closed liangde-chen closed 4 years ago

liangde-chen commented 4 years ago

I have some kaitai file like this:

types:
  setting_t:
    seq:
    - id: profile_id
      type: u4
      enum: profile_ids
enums:
  profile_ids:
    0x00000003: defaults                # Known default value is used.
    0xFFFFFFFF: not_found               # Value not found.

And the generated java code failed to be compiled: NOT_FOUND(4294967295); Error: integer number too large.

valery1707 commented 4 years ago

Sorry, but this problem addressed not to kaitai-gradle-plugin/kaitai-maven-plugin, because this plugins simply use https://github.com/kaitai-io/kaitai_struct_compiler to convert *.ksy files into *.java files and then compiles them.

This problem is in JavaCompiler::enumDeclaration: enums consist of id of type Long and label of type String. Generated enum class has constructor with argument of type long, but value 4294967295 on compile time interpreted as int and this value is out of integer range.

P.S. I created https://github.com/kaitai-io/kaitai_struct_compiler/pull/186 with fix.

valery1707 commented 4 years ago

@liangde-chen PR into kaitai_struct_compiler was merged. You need to wait for new release of kaitai_struct_compiler.