pax_global_header00006660000000000000000000000064143457712350014525gustar00rootroot0000000000000052 comment=c1e37c09b531b14ae12a501eb6fd529b31cecdaa golang-github-josharian-native-1.1.0/000077500000000000000000000000001434577123500175135ustar00rootroot00000000000000golang-github-josharian-native-1.1.0/doc.go000066400000000000000000000004461434577123500206130ustar00rootroot00000000000000// Package native provides easy access to native byte order. // // Usage: use native.Endian where you need the native binary.ByteOrder. // // Please think twice before using this package. // It can break program portability. // Native byte order is usually not the right answer. package native golang-github-josharian-native-1.1.0/endian_big.go000066400000000000000000000005471434577123500221270ustar00rootroot00000000000000//go:build mips || mips64 || ppc64 || s390x // +build mips mips64 ppc64 s390x package native import "encoding/binary" // Endian is the encoding/binary.ByteOrder implementation for the // current CPU's native byte order. var Endian = binary.BigEndian // IsBigEndian is whether the current CPU's native byte order is big // endian. const IsBigEndian = true golang-github-josharian-native-1.1.0/endian_generic.go000066400000000000000000000015171434577123500230000ustar00rootroot00000000000000//go:build !mips && !mips64 && !ppc64 && !s390x && !amd64 && !386 && !arm && !arm64 && !loong64 && !mipsle && !mips64le && !ppc64le && !riscv64 && !wasm // +build !mips,!mips64,!ppc64,!s390x,!amd64,!386,!arm,!arm64,!loong64,!mipsle,!mips64le,!ppc64le,!riscv64,!wasm // This file is a fallback, so that package native doesn't break // the instant the Go project adds support for a new architecture. // package native import ( "encoding/binary" "log" "runtime" "unsafe" ) var Endian binary.ByteOrder var IsBigEndian bool func init() { b := uint16(0xff) // one byte if *(*byte)(unsafe.Pointer(&b)) == 0 { Endian = binary.BigEndian IsBigEndian = true } else { Endian = binary.LittleEndian IsBigEndian = false } log.Printf("github.com/josharian/native: unrecognized arch %v (%v), please file an issue", runtime.GOARCH, Endian) } golang-github-josharian-native-1.1.0/endian_little.go000066400000000000000000000007171434577123500226620ustar00rootroot00000000000000//go:build amd64 || 386 || arm || arm64 || loong64 || mipsle || mips64le || ppc64le || riscv64 || wasm // +build amd64 386 arm arm64 loong64 mipsle mips64le ppc64le riscv64 wasm package native import "encoding/binary" // Endian is the encoding/binary.ByteOrder implementation for the // current CPU's native byte order. var Endian = binary.LittleEndian // IsBigEndian is whether the current CPU's native byte order is big // endian. const IsBigEndian = false golang-github-josharian-native-1.1.0/endian_test.go000066400000000000000000000006441434577123500223430ustar00rootroot00000000000000package native_test import ( "encoding/binary" "testing" "github.com/josharian/native" ) func TestPrintEndianness(t *testing.T) { t.Logf("native endianness is %v", native.Endian) var want binary.ByteOrder = binary.BigEndian if !native.IsBigEndian { want = binary.LittleEndian } if native.Endian != want { t.Errorf("IsBigEndian = %v not consistent with native.Endian = %T", native.IsBigEndian, want) } } golang-github-josharian-native-1.1.0/go.mod000066400000000000000000000000541434577123500206200ustar00rootroot00000000000000module github.com/josharian/native go 1.13 golang-github-josharian-native-1.1.0/license000066400000000000000000000020441434577123500210600ustar00rootroot00000000000000Copyright 2020 Josh Bleecher Snyder Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. golang-github-josharian-native-1.1.0/readme.md000066400000000000000000000004551434577123500212760ustar00rootroot00000000000000Package native provides easy access to native byte order. `go get github.com/josharian/native` Usage: Use `native.Endian` where you need the native binary.ByteOrder. Please think twice before using this package. It can break program portability. Native byte order is usually not the right answer.