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

Support for list value instances #14

Open
pfroud opened this issue Jun 27, 2022 · 3 comments
Open

Support for list value instances #14

pfroud opened this issue Jun 27, 2022 · 3 comments

Comments

@pfroud
Copy link
Contributor

pfroud commented Jun 27, 2022

KSY file:

meta:
  id: value_instance_list
instances:
  value_instance_list:
    value: "[0.1, 0.2]"

Compiled Java code:

 public ArrayList<Double> valueInstanceList() { ... }

Right now, kaitai_struct_model creates a SimpleNode where the value is an ArrayList, because of this isPresent check:

f55d911#diff-35a4962b04608dbbd0bbf57c37dd15b866476c46f96151f5d70c9cef4b21ac93R169

I am wondering if the isPresent check is still needed - if I comment it out, it looks like everything works correctly.

@Mingun
Copy link
Owner

Mingun commented Jun 27, 2022

Originally I made this check because value instance can have an arbitrary expression and it's unclear would we able to process individual list elements. Maybe this check is unnecessary. Feel free to submit a PR.

@pfroud
Copy link
Contributor Author

pfroud commented Jun 28, 2022

Here are the list value instances I've tried, which work OK:

List data type Line in KSY file Compiled Java
bytes value: "[[0,1], [2,3]]" new ArrayList<byte[]>(Arrays.asList(new byte[] { 0, 1 }, new byte[] { 2, 3 }))
integer value: "[300, 301]" new ArrayList<Integer>(Arrays.asList(300, 301))
float value: "[0.1, 0.2]" new ArrayList<Double>(Arrays.asList(0.1, 0.2))
enum value: "[my_enum::one, my_enum::two]" new ArrayList<MyEnum>(Arrays.asList(MyEnum.ONE, MyEnum.TWO))
boolean value: "[true, false]" new ArrayList<Boolean>(Arrays.asList(true, false))
string value: "['hello', 'world']" new ArrayList<String>(Arrays.asList("hello", "world"))
struct Don’t know how to do this
mixed value: "[false, 0.1]" KSC error: "can't combine output types: CalcBooleanType vs CalcFloatType"

Can you think of anything else to test?
I will open a pull request (#15).

@Mingun
Copy link
Owner

Mingun commented Jun 28, 2022

Thanks for the tests! To test struct you can use the following KSY:

meta:
  id: tests
seq:
  - id: struct1
    type: struct
  - id: struct2
    type: struct
instances:
  value:
    value: '[struct1, struct2]'
types:
  struct:
    seq:
      - id: field
        type: u1

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

No branches or pull requests

2 participants