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

LITTLE_ENDIAN - does not work! #3

Open
GoogleCodeExporter opened this issue Jun 23, 2015 · 1 comment
Open

LITTLE_ENDIAN - does not work! #3

GoogleCodeExporter opened this issue Jun 23, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Your System almost works!!! BUT Conversion with little endian does not work. It 
seems like you forgot to impliment byteorder when unpacking?? It is really 
unfortunate because I am soo close to get it working a serial protocol for 
arduino. 

You can reproduce the problem with the code below:


@StructClass
public class Foo{
    @StructField(order = 0)
    public int b;
    @StructField(order = 1)
    public int i;
}

try{
    // Pack the class as a byte buffer
    Foo f = new Foo();
    f.b = (int)14;
    f.i = 12;
    byte[] b = JavaStruct.pack(f,ByteOrder.LITTLE_ENDIAN );

    // Unpack it into an object
    Foo f2 = new Foo();
    JavaStruct.unpack(f2, b,ByteOrder.LITTLE_ENDIAN );
    println(f2.b);
}
catch(StructException e){
}
  et_begin();
  size(800, 600);
}

Original issue reported on code.google.com by [email protected] on 26 Jun 2014 at 8:46

@GoogleCodeExporter
Copy link
Author

Since we are only using short (8bit = 2 bytes) we have solved it with this 
nasty solution:

 try {
    // Pack the class as a byte buffer
    Foo f = new Foo();
    f.b = (int)14;
    f.i = 12;
    byte[] b = JavaStruct.pack(f, ByteOrder.LITTLE_ENDIAN );
    byte[] c = new byte[b.length];
  /*  for(int i =0; i < b.length;i++)
    {
      c[i] = b[b.length -i-1];

    }*/
    for(int i=0; i < b.length-1;i=i+2)
    {
      c[i] = b[i+1];
      c[i+1] = b[i];
    }
    // Unpack it into an object
    Foo f2 = new Foo();
    JavaStruct.unpack(f2, c );
    println(f2.b);
  }
  catch(StructException e) {
  }

Original comment by [email protected] on 26 Jun 2014 at 9:05

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

1 participant