kaitai_struct_java_runtime icon indicating copy to clipboard operation
kaitai_struct_java_runtime copied to clipboard

Add ability to report positions relative to root stream and add PositionInfo interface

Open Mingun opened this issue 5 years ago • 4 comments

Runtime changes for https://github.com/kaitai-io/kaitai_struct_compiler/pull/197

Mingun avatar Feb 23 '20 20:02 Mingun

@generalmimon, thanks for review! I post some answers with explanation of my minds when I made these changes and if you find they unconvincing, just say and I'll apply your suggestions.

Also, over the time, I'm noticed, that usually things like Region called Span (ex: C#, Rust), so I'm going to change names accordingly

Mingun avatar Nov 16 '20 14:11 Mingun

There's also an important thing to consider: creating a stream on processed bytes, for example with process: zlib (kudos to @GreyCat and his https://github.com/kaitai-io/kaitai_struct/issues/331#issuecomment-361432895 that reminded me of it). The decompression gives you a brand new block of data and the bytes and stream positions don't map to anything in the original root file stream. In fact, you get another root stream.

generalmimon avatar Nov 16 '20 22:11 generalmimon

Good point! But need to notice, that the such problem exists in the web-ide and maybe in the https://github.com/kaitai-io/kaitai_struct_visualizer.

To solve that problem we can track which root Span belongs to, for example, by assign unique identifiers to the each root, created by the process key, or for the each Span to store its parent Span:

class Span {
  private final long offset;
  private final long long start;
  private long end = -1;


  private final int rootCategory;
  //-OR-
  private final Span parent;
  ...
}

Each root Span will have root = null

Mingun avatar Nov 17 '20 15:11 Mingun

Implementation of tags for different stream origins I'll push later. Anyway, it's needed only for correct interpretation of offsets, so maybe even another PR will be preferrable

Mingun avatar Nov 19 '20 17:11 Mingun