2020-05-04 20:46:48 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NativeEndian is set to either binary.BigEndian or binary.LittleEndian,
|
|
|
|
// depending on the host's endianness.
|
|
|
|
var NativeEndian binary.ByteOrder
|
|
|
|
|
2021-07-02 08:43:15 +00:00
|
|
|
// Clang is set to either "el" or "eb" depending on the host's endianness.
|
|
|
|
var ClangEndian string
|
|
|
|
|
2020-05-04 20:46:48 +00:00
|
|
|
func init() {
|
|
|
|
if isBigEndian() {
|
|
|
|
NativeEndian = binary.BigEndian
|
2021-07-02 08:43:15 +00:00
|
|
|
ClangEndian = "eb"
|
2020-05-04 20:46:48 +00:00
|
|
|
} else {
|
|
|
|
NativeEndian = binary.LittleEndian
|
2021-07-02 08:43:15 +00:00
|
|
|
ClangEndian = "el"
|
2020-05-04 20:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func isBigEndian() (ret bool) {
|
|
|
|
i := int(0x1)
|
|
|
|
bs := (*[int(unsafe.Sizeof(i))]byte)(unsafe.Pointer(&i))
|
|
|
|
return bs[0] == 0
|
|
|
|
}
|