Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lengths and other relations in data #29

Closed
KOLANICH opened this issue Sep 13, 2016 · 2 comments
Closed

Lengths and other relations in data #29

KOLANICH opened this issue Sep 13, 2016 · 2 comments
Assignees
Labels

Comments

@KOLANICH
Copy link

KOLANICH commented Sep 13, 2016

Is it possible to define a structure where the first field is the count (let's call it n) followed by array of n items of some smaller structure followed by the rest of structure.
In pseudo-c++

struct a{
//.....
};
struct b{
size_t count;
a data[count];
//rest of structure
}

Also variants are needed, where the type of field depends on combinational function of bit flags. For example if we process network packets, their content depends on the header. This can be japped to the language using polymophism.

@GreyCat
Copy link
Member

GreyCat commented Sep 13, 2016

Yeah, it's possible right now using repeat. The rough translation of your example in .ksy would be:

types:
  a:
    # .....
  b:
    seq:
      - id: count
        type: u4 # or whatever size_t maps to
      - id: data
        type: a
        repeat: expr
        repeat-expr: count

Conditionals are also supported. if is available in v0.5 (stable release, as of now), newer versions would include switch to avoid writing lots of ifs.

@GreyCat GreyCat closed this as completed Sep 13, 2016
@GreyCat GreyCat self-assigned this Sep 13, 2016
@KOLANICH
Copy link
Author

OK, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants