Created
March 21, 2021 03:12
-
-
Save raspi/360811bd32eba0ac40e834d85ab1c0f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nativeEndian binary.ByteOrder | |
func init() { | |
buf := [2]byte{} | |
*(*uint16)(unsafe.Pointer(&buf[0])) = uint16(0xABCD) | |
switch buf { | |
case [2]byte{0xCD, 0xAB}: | |
nativeEndian = binary.LittleEndian | |
case [2]byte{0xAB, 0xCD}: | |
nativeEndian = binary.BigEndian | |
default: | |
panic("Could not determine native endianness.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment