kaitai-io / kaitai_struct

Kaitai Struct: declarative language to generate binary data parsers in C++ / C# / Go / Java / JavaScript / Lua / Nim / Perl / PHP / Python / Ruby
https://kaitai.io
3.93k stars 193 forks source link

How to access seq id and type strings from ksy file in KSC scala? #710

Open glass-ships opened 4 years ago

glass-ships commented 4 years ago

Using this ksy for reference-

I'm wondering how I can generate, for example animal_entry_t , m_entry, weight, etc. generally?

Things like ${privateMemberName(id)} are scoped only within certain functions, and some like ${types2class(typeProvider.nowClass.name)} return different strings depending on where they are called.

Is there a consistent way to access the ids and types described in a ksy file?

KOLANICH commented 4 years ago

Currently it is not possible to access the data from the original KSY. I remember there was an issue about it.

The names of variables are though derived from id in known way. More precisely, the names are transformed from snake_lower_case to the style convention used in the lang. If there are no trailing and leading underscores, you can compute the original names given language-specific variable names.

glass-ships commented 4 years ago

Ah, apologies - so this is in the context of kaitai-struct-compiler, so the language in question is scala .

Currently I'm working on implementing a new target language, cpp_awk which will use C++ to store data in Awkward arrays.

The fork can be found here

What I'm really wondering is whether the classes in scala allow me to access those variable names, and how to do so.

glass-ships commented 4 years ago

So I've done some investigating and inside ConstructClassCompiler.scala there's an instance where ClassSpecs gets passed in, which may contain the information i need.

Does anyone know of a way to inspect this class in command line, and see what objects it contains? Perhaps using sbt in command line?

glass-ships commented 4 years ago

Just bumping this thread in case anyone has some thoughts