diff options
| author | BiSaXa <1669855+BiSaXa@users.noreply.github.com> | 2022-08-27 18:53:13 +0300 |
|---|---|---|
| committer | BiSaXa <1669855+BiSaXa@users.noreply.github.com> | 2022-08-27 18:53:13 +0300 |
| commit | 0a3082bd167b2caa1d4a54b62d72e8be13ff43b0 (patch) | |
| tree | a5d1c167da7015ccef4d9c3c5677e01f664850ba /utils | |
| parent | support for multiple demos in a folder as an argument (diff) | |
| download | sdp.go-0a3082bd167b2caa1d4a54b62d72e8be13ff43b0.tar.gz sdp.go-0a3082bd167b2caa1d4a54b62d72e8be13ff43b0.tar.bz2 sdp.go-0a3082bd167b2caa1d4a54b62d72e8be13ff43b0.zip | |
some stuff before i realized i need my own bitreader library
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/utils.go | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/utils/utils.go b/utils/utils.go index 62924c2..77e87af 100644 --- a/utils/utils.go +++ b/utils/utils.go | |||
| @@ -6,8 +6,6 @@ import ( | |||
| 6 | "math" | 6 | "math" |
| 7 | "os" | 7 | "os" |
| 8 | "unsafe" | 8 | "unsafe" |
| 9 | |||
| 10 | "github.com/potterxu/bitreader" | ||
| 11 | ) | 9 | ) |
| 12 | 10 | ||
| 13 | func ReadByteFromFile(file *os.File, size int32) []byte { | 11 | func ReadByteFromFile(file *os.File, size int32) []byte { |
| @@ -22,15 +20,28 @@ func CheckError(e error) { | |||
| 22 | } | 20 | } |
| 23 | } | 21 | } |
| 24 | 22 | ||
| 25 | func CheckFirstBit(byteArr []byte) bool { | 23 | /* |
| 26 | reader := bitreader.BitReader(byteArr) | 24 | github.com/32bitkid/bitreader |
| 27 | state, err := reader.ReadBit() | ||
| 28 | if err != nil { | ||
| 29 | state = false | ||
| 30 | } | ||
| 31 | return state | ||
| 32 | } | ||
| 33 | 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 | */ | ||
| 34 | func IntFromBytes(byteArr []byte) uint32 { | 45 | func IntFromBytes(byteArr []byte) uint32 { |
| 35 | int := binary.LittleEndian.Uint32(byteArr) | 46 | int := binary.LittleEndian.Uint32(byteArr) |
| 36 | return int | 47 | return int |