-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Pack and unpack array of "Structs" #59
Comments
Please do send a test case.
You can try struc.UnpackWithOptions(r, i, &struc.Options{Order: binary.LittleEndian})
Can you try unpacking a slice instead of array? like unpackedData[:]
|
Also the syntax &[2]LEData{} is a little silly, you should probably remove the & and think about generally passing around a slice instead of pointer to array.
… On Apr 11, 2018, at 6:14 AM, Andy Hampshire ***@***.***> wrote:
I found an strange error when working with an array of structs.
Pack and unpack work correct as far as i can see with one issue ... it ignores the Endian setting (little).
For example unpack a byte stream that contains little endian floats ...
type LEData struct {
X float32 struc:"float32,little" // world co-ordinates of vehicle
Y float32 struc:"float32,little" // world co-ordinates of vehicle
Z float32 struc:"float32,little" // world co-ordinates of vehicle
}
unpackedData := &LEData{}
err = struc.Unpack(buf2, unpackedData)
The data is actually an array of these items...
unpackedData := &[2]LEData{}
err = struc.Unpack(buf2, unpackedData)
The unpack "works" no errors at least :-) ..... but the data has been interpreted as Big Endian even though the data is tagged as Little.
Let me know if you need a working test case....
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Not sure how it got like that in the first place ;-) I'll try the Options syntax and create you a small test case, as soon as i have time. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found an strange error when working with an array of structs.
Pack and unpack work correct as far as i can see with one issue ... it ignores the Endian setting (little).
For example unpack a byte stream that contains little endian floats ...
type LEData struct {
X float32
struc:"float32,little"
// world co-ordinates of vehicleY float32
struc:"float32,little"
// world co-ordinates of vehicleZ float32
struc:"float32,little"
// world co-ordinates of vehicle}
unpackedData := &LEData{}
err = struc.Unpack(buf2, unpackedData)
Data is correct ... However ...
The data is actually an array of these items...
unpackedData := &[2]LEData{}
err = struc.Unpack(buf2, unpackedData)
The unpack "works" no errors at least :-) ..... but the data has been interpreted as Big Endian even though the data is tagged as Little.
Let me know if you need a working test case....
The text was updated successfully, but these errors were encountered: