27 lines
490 B
Go
27 lines
490 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"unsafe"
|
||
|
)
|
||
|
|
||
|
func isLittleEndian() bool {
|
||
|
var placeHolder uint32 = 0x0000FFFF
|
||
|
return (*[4]byte)(unsafe.Pointer(&placeHolder))[0] == 0xFF
|
||
|
}
|
||
|
|
||
|
func be32toh(host uint32) uint32 {
|
||
|
if isLittleEndian() {
|
||
|
return ((host & 255) << 24) | (((host >> 8) & 255) << 16) | (((host >> 16) & 255) << 8) | (host >> 24)
|
||
|
} else {
|
||
|
return host
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func be16toh(host uint16) uint16 {
|
||
|
if isLittleEndian() {
|
||
|
return ((host & 255) << 8) | (host >> 8)
|
||
|
} else {
|
||
|
return host
|
||
|
}
|
||
|
}
|