Skip to content

"Expression is empty" error when using arrays #21

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

Closed
timmattison opened this issue Jul 31, 2018 · 8 comments
Closed

"Expression is empty" error when using arrays #21

timmattison opened this issue Jul 31, 2018 · 8 comments
Assignees
Milestone

Comments

@timmattison
Copy link
Contributor

timmattison commented Jul 31, 2018

I have a parent class:

import com.igormaznitsa.jbbp.mapper.Bin;

public class BreakJBBPDslBuilderParent {
    @Bin(outOrder = 1)
    public BreakJBBPDslBuilderChild[] breakJBBPDslBuilderChildArray;
}

And a child class:

import com.igormaznitsa.jbbp.mapper.Bin;
import com.igormaznitsa.jbbp.mapper.BinType;

public class BreakJBBPDslBuilderChild {
    @Bin(outOrder = 1, comment = "Reserved", type = BinType.BYTE)
    public byte reserved;
}

If I try to use the JBBPDslBuilder on the parent class like this:

JBBPDslBuilder.Begin().AnnotatedClass(BreakJBBPDslBuilderParent.class).End();

I get an IllegalArgumentException with the message "Expression is empty" that is thrown by this line:

throw new IllegalArgumentException("Expression is empty");

Is this the correct way I'd use the JBBPDslBuilder to work with a structure that has arrays in it?

@raydac
Copy link
Owner

raydac commented Aug 1, 2018

and what do you use as child class? you have provided duplication of parent class instead of child class

@raydac
Copy link
Owner

raydac commented Aug 1, 2018

if you have an array field then DSL builder needs information about length of the array and it should be provided through expression in extra attribute

 class BreakJBBPDslBuilder {
      @Bin(outOrder = 1, comment = "Reserved", type = BinType.BIT_ARRAY, extra = "4")
      public byte[] reserved;
    }

@timmattison
Copy link
Contributor Author

I will update that in a minute. But the child class should just have a single byte field in it.

@timmattison
Copy link
Contributor Author

Updated the child object. I was using this with the binary code I committed on another branch and the output I get from that is this:

breakJBBPDslBuilderChildArray [_] { BYTE reserved; } 

To me that makes the most sense. Can this be supported? I'd like to combine efforts here and have this wrapped into your library rather than maintain the external interface I built.

@timmattison
Copy link
Contributor Author

timmattison commented Aug 1, 2018

If you check out that branch and want to simply run this in a test to see what it does you can use this JUnit test code:

import org.junit.Test;

import java.io.IOException;

public class BinaryTest {
    @Test
    public void test1() throws IOException {
        System.out.println(new BreakJBBPDslBuilderParent().getFormat());
    }
}

@raydac raydac self-assigned this Aug 1, 2018
@raydac raydac added this to the 1.4.1 milestone Aug 1, 2018
@raydac
Copy link
Owner

raydac commented Aug 1, 2018

I have improved message in the exception to provide more information what does mean the error and how to fix
Bin annotation can be used not only for DSL builder but also for JBBPOut so that it is important to provide all correct info in Bin annotation for a field

@timmattison
Copy link
Contributor Author

If the field is going to be an array without a fixed size (e.g. a structure that repeats 0 or more times) what is the size I should specify there? Do I use the underscore like the DSL?

@raydac
Copy link
Owner

raydac commented Aug 2, 2018

if array should be read till end of stream then underscore should be used, extra="_"

@raydac raydac closed this as completed Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants