binary.ByteOrder

100 views
Skip to first unread message

Stephen Illingworth

unread,
Aug 10, 2023, 6:46:21 AM8/10/23
to golang-nuts
Hello,

I want to detect the implementation of binary.ByteOrder. ie. whether it is Little Endian or Big Endian.

Normally, you would do this with a type assertion or a type switch but in the case of the binary package the little/big endian implementations are not exported.

The only way that I can see to distinguish between the implementations is to test the value returned by String(). Am I missing something here or should I continue to use String()?

Regards
Stephen

Rob Pike

unread,
Aug 10, 2023, 9:16:53 AM8/10/23
to Stephen Illingworth, golang-nuts

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/67469c8a-b1aa-4976-8f4a-2b4458d28214n%40googlegroups.com.

Stephen Illingworth

unread,
Aug 10, 2023, 9:27:49 AM8/10/23
to golang-nuts
Thanks. Although I'm not worried about the native byte order of my machine

I'm writing an ARM emulator. The endianness of the ARM I'm taking to be whatever the endianess is in the ELF file from which I'm loading the program. I'm using the debug/elf package in the standard library which in turn uses the binary package

Generally, the specifics of the byte order is irrelevant - I can just use Uint32(), PutUint32() etc. but in some specific instructions it's easier to handle the byte order manually and for that I need to know what the endianness is.

I can work around it but I just thought I might be missing something.


Regards
Stephen

TheDiveO

unread,
Aug 10, 2023, 10:25:59 AM8/10/23
to golang-nuts
https://github.com/google/nftables/blob/main/binaryutil/binaryutil.go ... could give you some bad ideas; we need it for Linux nftables that encodes stuff in host endianess.
Reply all
Reply to author
Forward
0 new messages