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

short[] causes broken code #59

Open
rekire opened this issue Jul 27, 2016 · 4 comments
Open

short[] causes broken code #59

rekire opened this issue Jul 27, 2016 · 4 comments

Comments

@rekire
Copy link

rekire commented Jul 27, 2016

I already read in the readme.md that you don't support that type, but the generated code does not compile. If you have some time please fix that.

@DariusL
Copy link

DariusL commented Jul 27, 2016

That's how "not supported" is implemented. You can generate the entire class and change the parts that read and write your array. What other solution would you recommend?

@rekire
Copy link
Author

rekire commented Jul 28, 2016

I would prefer if the generated code would just work^^

Here is the generated code from my own library:

// read from the parcable
int[] shortArrayAsIntArray = in.createIntArray();
shortArray = new short[shortArrayAsIntArray.length];
for(int i = 0; i < shortArrayAsIntArray.length; i++) {
    shortArray[i] = (short)shortArrayAsIntArray[i];
}

// write to the parcable
int[] shortArrayAsIntArray = new int[shortArray.length];
for(int i = 0; i < shortArrayAsIntArray.length; i++) {
    shortArrayAsIntArray[i] = (int)shortArray[i];
}
dest.writeIntArray(shortArrayAsIntArray);

Currently will be this code generated which won't compile:

// write to the parcable
dest.writeParcelable(this.shortArray, flags);
// read from the parcable
this.shortArray = in.readParcelable(short[].class.getClassLoader());

@DariusL
Copy link

DariusL commented Jul 28, 2016

I agree that the feature is useful, I'm just saying that the best failure is an early failure. Your code would work, I don't know if this plugin can generate a utils class with methods for conversion, though. So you'll have to keep this code in every task.

Other than that, you could probably pack two shorts into an int for memory efficiency, but you'll need benchmarks to check if that helps.

@rekire
Copy link
Author

rekire commented Jul 28, 2016

If you talk about memory efficiency keep in mind that every boolean is stored as byte or even as integer. They can been packed much more efficiency.

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