2

I am trying to pass a parameter to ksy file. The parameter is of type another ksy file. The reason is that i need to access all the fields from the ksy file passed as parameter. Is that possible? If yes, would you please provide me with syntax code snippet so I can mimic it. If no, what would be another solution?

Thank You.

enter image description here

enter image description here

Ossama
  • 45
  • 3
  • It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output / tracebacks). The more detail you provide, the more answers you are likely to receive. Check the [FAQ](https://stackoverflow.com/tour) and [How to Ask](https://stackoverflow.com/help/how-to-ask). – THess Feb 12 '20 at 07:21
  • I have updated the question and added screenshots to explain what i am trying to achieve, any help would be much appreciated – Ossama Feb 20 '20 at 06:12

1 Answers1

1

Affiliate disclaimer: I'm a Kaitai Struct maintainer (see my GitHub profile).

First, I recommend always using the development version of the Kaitai Struct Web IDE (https://ide.kaitai.io/devel/), not the stable one. The stable IDE deployed at https://ide.kaitai.io/ has KS compiler of version 0.8, which is indeed the latest stable version, but already 2 years old at the moment. But the project is under active development, new bug fixes and improvements are coming every week, so the stable Web IDE is pretty much outdated. And thanks to the recent infrastructure enhancement, the devel Web IDE now gets rebuilt every time the compiler is updated, so you can use even the most recent features.

However, you won't be able to simulate the particular situation you describe in the Web IDE, because it can't currently handle top-level parameteric types (there is no hook where you can pass your own values as arguments). But it should work in a local environment. You can compile the commontype.ksy and pty.ksy specs in the Web IDE to the target language you want to use (the manual shows how to do it). The code putting it together could look like this (Java):

Commontype ct = new Commontype(new ByteBufferKaitaiStream(new byte[] { 80, 75 }));
Pty r = new Pty(
    new ByteBufferKaitaiStream(new byte[] { 80 }), // IO stream
    ct // commonword
);

Note that the actual parameter order of the Pty constructor may be different, e.g. in Python come the custom params (commonword) first and then the IO object. Check the generated code in your particular language.

Petr Pucil
  • 185
  • 1
  • 5
  • any news after 2 years? How can I use javascript to pass to a ksy-based .js file a parameter to be used by the file? (I am writing a library which reads an image, but the file format changes depending on image size, which is specified in a text label at the beginning of the file, which has a not-constant offset....) – jumpjack Jul 04 '22 at 13:15