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
encoding/binary: binary.Read doesn't respect byteOrder when []byte is passed #40891
Comments
This is because the byte ordering is the byte ordering of the target type which has no meaning when the target is only 8 bits wide. Said another way, guid is 16 bytes. That’s it, no endianness needed. |
@davecheney Thank you for comment.
It is an element size (not an entire slice).
I think we should take care endianness. MS supports a GUID API to avoid Guid endianness issue. (refer to Remarks) |
it supports integer types of varying but sizes. If you decode into something larger than a byte then endianness comes into play. |
You can always reverse your byte slice after reading.
|
@davecheney @randall77 Thank you for comment and example code ! I understood binary.Read doesn't support what I want to do. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried to read 6 bytes using binary.Read in BigEndian.
https://play.golang.org/p/RUvRdkc0a0W
What did you expect to see?
What did you see instead?
binary.Read returns same value and it seems to ignore byteOrder.
Background:
The GUID Partition Table (GPT) has mixed endian GUID.
Refer to https://developer.apple.com/library/archive/technotes/tn2166/_index.html#//apple_ref/doc/uid/DTS10003927-CH1-SECTION2
The GUID is encoded like
The point is the last 6bytes
0x00 0xa0 0xc9 0x3e 0xc9 0x3b
. It is encoded as Big Endian.How can we get using binary.Read ?
Does binary.Read support such case?
The text was updated successfully, but these errors were encountered: