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.97k stars 192 forks source link

Number ranges in switch #130

Open KOLANICH opened 7 years ago

KOLANICH commented 7 years ago

Sometimes you need to perform the same action for a range of numbers. for example

0000 : reserved 0001 : 192 samples 0010-0101 : 576 (2^(n-2)) samples, i.e. 576/1152/2304/4608 0110 : get 8 bit (blocksize-1) from end of header 0111 : get 16 bit (blocksize-1) from end of header 1000-1111 : 256 (2^(n-8)) samples, i.e. 256/512/1024/2048/4096/8192/16384/32768

so I propose to allow number ranges in switch.

GreyCat commented 7 years ago

Possible, but pretty bothersome from implementation POV. One needs to:

Help would be appreciated.