Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums bugs #139

Open
d0d04m3 opened this issue Oct 4, 2021 · 3 comments
Open

Enums bugs #139

d0d04m3 opened this issue Oct 4, 2021 · 3 comments
Labels

Comments

@d0d04m3
Copy link

d0d04m3 commented Oct 4, 2021

so i use https://ide.kaitai.io/
and use this file
samples/sample1.zip
and this my code

meta:
  id: animal_record
  endian: be
seq:
    - id: frametype
      type: u1
      enum: frame
enums:
    frame:
      0x10: fixed
      0x68: variable

and this my resualts
frametype = FIXED|VARIABLE (0x50 = 80)
how that its worng

@generalmimon generalmimon transferred this issue from kaitai-io/kaitai_struct Jun 15, 2022
@wader
Copy link

wader commented Apr 11, 2023

Stumbled upon this also. Reading the webide code gave me come clues what us going on. As i understand this flags behavior is webide specific and is not part of generated code? can't find anything about it in the guide.

var flagCheck = 0, flagSuccess = true;
var flagStr = Object.keys(enumObj).filter(x => isNaN(<any>x)).filter(x => {
if (flagCheck & enumObj[x]) {
flagSuccess = false;
return false;
}
flagCheck |= enumObj[x];
return obj & enumObj[x];
}).join("|");
//console.log(debug.enumName, enumObj, enumObj[obj], flagSuccess, flagStr);
result.enumStringValue = enumObj[obj] || (flagSuccess && flagStr);

@generalmimon
Copy link
Member

Reading the webide code gave me come clues what us going on. As i understand this flags behavior is webide specific and is not part of generated code?

Yes, this is a misfeature of the Web IDE that doesn't respect how KS enums work. Currently, KS enums are strictly one-to-one bi-directional mappings between integer constants and identifiers (one integer value can be assigned to at most one identifier and one identifier can't be used more than once). The presence of an enum member is always based on equality - so an integer converted to an enum type matches at most one member in the enum.

@wader
Copy link

wader commented Apr 12, 2023

@generalmimon Good to know. It confused me a bit as my case it only showed one enum name (no "|") so thought i had missed something how enums work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants