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

In debug mode generated classes must implement special debug interfaces #27

Open
Mingun opened this issue Feb 6, 2020 · 4 comments · May be fixed by kaitai-io/kaitai_struct_compiler#197

Comments

@Mingun
Copy link
Contributor

Mingun commented Feb 6, 2020

Currently to obtain debug maps with positions you must use reflection. That looks ugly, because you need to catch checked exceptions, that never will be thrown.

I suggest to add to runtime special interfaces, that will be implemented by generated classes when debug mode is activated.

@GreyCat
Copy link
Member

GreyCat commented Feb 8, 2020

I don't quite understand the idea yet — maybe you can go on with some proof of concept code to illustrate how we can avoid reflection?

@Mingun
Copy link
Contributor Author

Mingun commented Feb 8, 2020

public interface PositionInfo {
  Map<String, Integer> attrStart();
  Map<String, Integer> attrEnd();
  Map<String, ? extends List<Integer>> arrStart();
  Map<String, ? extends List<Integer>> arrEnd();
}

final KaitaiStruct struct = …;
// Generator generates classes, that implements this interface,
// if debug mode/positions-info is enabled
if (struct instanceof PositionInfo) {
  final PositionInfo info = (PositionInfo)struct;
  //...
}

@GreyCat
Copy link
Member

GreyCat commented Feb 8, 2020

Sure, this makes sense. Let's do it!

@Mingun
Copy link
Contributor Author

Mingun commented Feb 8, 2020

I'll prepare PR in next couple days, where I also plan to change the way information is stored to solve issue #26. I plan to store both positions -- relative to current IO object and relative to root IO object. This will solve problems with showing incorrect regions in https://github.com/kaitai-io/kaitai_struct_gui (see #26).

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