diff options
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/utils.go | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/utils/utils.go b/utils/utils.go index 77e87af..6db28b0 100644 --- a/utils/utils.go +++ b/utils/utils.go | |||
| @@ -4,10 +4,19 @@ import ( | |||
| 4 | "encoding/binary" | 4 | "encoding/binary" |
| 5 | "log" | 5 | "log" |
| 6 | "math" | 6 | "math" |
| 7 | "math/bits" | ||
| 7 | "os" | 8 | "os" |
| 8 | "unsafe" | 9 | "unsafe" |
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 12 | func ReverseByteArrayValues(byteArr []byte, size int) []byte { | ||
| 13 | arr := make([]byte, size) | ||
| 14 | for index, byteValue := range byteArr { | ||
| 15 | arr[index] = bits.Reverse8(byteValue) | ||
| 16 | } | ||
| 17 | return arr | ||
| 18 | } | ||
| 19 | |||
| 11 | func ReadByteFromFile(file *os.File, size int32) []byte { | 20 | func ReadByteFromFile(file *os.File, size int32) []byte { |
| 12 | tmp := make([]byte, size) | 21 | tmp := make([]byte, size) |
| 13 | file.Read(tmp) | 22 | file.Read(tmp) |
| @@ -20,28 +29,6 @@ func CheckError(e error) { | |||
| 20 | } | 29 | } |
| 21 | } | 30 | } |
| 22 | 31 | ||
| 23 | /* | ||
| 24 | github.com/32bitkid/bitreader | ||
| 25 | |||
| 26 | func ReadBitsWithFirstBitCheckFromFile(file *os.File) (byteArr []byte, err error) { | ||
| 27 | arr := make([]byte, 4) | ||
| 28 | reader := bitreader.NewReader(file) | ||
| 29 | n := 0 | ||
| 30 | state, err := reader.Read1() | ||
| 31 | if err != nil || state == true { | ||
| 32 | return nil, fmt.Errorf("ERR or VAL in BIT CHECK") | ||
| 33 | } | ||
| 34 | n += 1 | ||
| 35 | if n == 0 { | ||
| 36 | val, err := reader.Read32(32) | ||
| 37 | if err != nil { | ||
| 38 | return nil, fmt.Errorf("ERR or VAL in BIT CHECK") | ||
| 39 | } | ||
| 40 | binary.LittleEndian.PutUint32(arr, val) | ||
| 41 | } | ||
| 42 | return arr, nil | ||
| 43 | } | ||
| 44 | */ | ||
| 45 | func IntFromBytes(byteArr []byte) uint32 { | 32 | func IntFromBytes(byteArr []byte) uint32 { |
| 46 | int := binary.LittleEndian.Uint32(byteArr) | 33 | int := binary.LittleEndian.Uint32(byteArr) |
| 47 | return int | 34 | return int |