From 4e71a481884c0c43aea3d0ee695ae68cdec56478 Mon Sep 17 00:00:00 2001 From: BiSaXa <1669855+BiSaXa@users.noreply.github.com> Date: Wed, 7 Sep 2022 19:40:16 +0300 Subject: first rewrite commit using bisaxa/bitreader --- utils/utils.go | 44 ++------------------------------------------ 1 file changed, 2 insertions(+), 42 deletions(-) (limited to 'utils/utils.go') diff --git a/utils/utils.go b/utils/utils.go index 5226e80..46b707c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,55 +1,15 @@ package utils -import ( - "encoding/binary" - "log" - "math" - "math/bits" - "os" - "unsafe" -) +import "os" func CheckError(e error) { if e != nil { - log.Panic(e) + panic(e) } } -func ReverseByteArrayValues(byteArr []byte, size int) []byte { - arr := make([]byte, size) - for index, byteValue := range byteArr { - arr[index] = bits.Reverse8(byteValue) - } - return arr -} - func ReadByteFromFile(file *os.File, size int32) []byte { tmp := make([]byte, size) file.Read(tmp) return tmp } - -func IntFromBytes(byteArr []byte) uint32 { - int := binary.LittleEndian.Uint32(byteArr) - return int -} - -func FloatFromBytes(byteArr []byte) float32 { - bits := binary.LittleEndian.Uint32(byteArr) - float := math.Float32frombits(bits) - return float -} - -func FloatArrFromBytes(byteArr []byte) []float32 { - if len(byteArr) == 0 { - return nil - } - - l := len(byteArr) / 4 - ptr := unsafe.Pointer(&byteArr[0]) - // It is important to keep in mind that the Go garbage collector - // will not interact with this data, and that if src if freed, - // the behavior of any Go code using the slice is nondeterministic. - // Reference: https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices - return (*[1 << 26]float32)((*[1 << 26]float32)(ptr))[:l:l] -} -- cgit v1.2.3