From a77cf8169b42a4394e62f7a381ca546b27d0f723 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 7 Nov 2022 16:09:44 +0300 Subject: starting fresh for the third time --- utils/utils.go | 62 ---------------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 utils/utils.go (limited to 'utils/utils.go') diff --git a/utils/utils.go b/utils/utils.go deleted file mode 100644 index db1b02f..0000000 --- a/utils/utils.go +++ /dev/null @@ -1,62 +0,0 @@ -package utils - -import ( - "bytes" - "os" - "unsafe" - - "github.com/pektezol/bitreader" -) - -func CheckError(e error) { - if e != nil { - panic(e) - } -} - -func ReadByteFromFile(file *os.File, size int32) []byte { - tmp := make([]byte, size) - file.Read(tmp) - return tmp -} - -func ReadStringFromFile(file *os.File) string { - var output string - reader := bitreader.Reader(file, true) - for { - value, err := reader.ReadBytes(1) - CheckError(err) - if value == 0 { - break - } - output += string(rune(value)) - } - return output -} - -func ReadStringFromSlice(file []byte) string { - var output string - reader := bitreader.Reader(bytes.NewReader(file), true) - for { - value, err := reader.ReadBytes(1) - CheckError(err) - if value == 0 { - break - } - output += string(rune(value)) - } - return output -} - -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