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
4.04k stars 199 forks source link

Param variables appears multiple times in the serialized JSON format #1139

Open atikj opened 1 month ago

atikj commented 1 month ago

Consider below ksy file

meta:
  id: abc2
  endian: le
  title: Project specific packets

params:
  - id: project_id
    type: u2

seq:
  - id: packet
    type:
      switch-on: project_id
      cases:
        1: project_id_1

When the binary data is serialized into JSON, we have observed that project_id field appears as member of sequence along with property packet? Also in the Kaitai generated files of GoLanguage, this params appears as a member variable of abc2 struct as well.

As per my understanding, this is default behavior of kaitai. In Kaitai Struct, when you define parameters in your KSY file, these parameters are often included as member variables in the generated classes (Go structs or Java classes). This is because the parameters are essential for the parsing logic and are treated as part of the object’s state. When these objects are serialized into JSON, the parameters appear as member variables.

Kindly confirm above behavior. How can we remove the appearance of params as member variables? We dont want that params to be appear as field in the serialized JSON. Is there any better approach to achieve that?