aboutsummaryrefslogtreecommitdiff
path: root/utils/bitreader.go
diff options
context:
space:
mode:
authorBiSaXa <1669855+BiSaXa@users.noreply.github.com>2022-09-07 19:40:16 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-09-16 21:39:36 +0300
commit4e71a481884c0c43aea3d0ee695ae68cdec56478 (patch)
treed75c96612526a7c686d9f4d85af6b89c7cd864e6 /utils/bitreader.go
parentfinal commit before rewrite (diff)
downloadsdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.tar.gz
sdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.tar.bz2
sdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.zip
first rewrite commit using bisaxa/bitreader
Diffstat (limited to 'utils/bitreader.go')
-rw-r--r--utils/bitreader.go94
1 files changed, 0 insertions, 94 deletions
diff --git a/utils/bitreader.go b/utils/bitreader.go
deleted file mode 100644
index ec7454e..0000000
--- a/utils/bitreader.go
+++ /dev/null
@@ -1,94 +0,0 @@
1package utils
2
3import (
4 "fmt"
5 "math"
6 "strconv"
7)
8
9func ReadButtonsDataFromInt32(input int32) []string {
10 buttonList := [32]string{
11 "Attack",
12 "Jump",
13 "Duck",
14 "Forward",
15 "Back",
16 "Use",
17 "Cancel",
18 "Left",
19 "Right",
20 "MoveLeft",
21 "MoveRight",
22 "Attack2",
23 "Run",
24 "Reload",
25 "Alt1",
26 "Alt2",
27 "Score",
28 "Speed",
29 "Walk",
30 "Zoom",
31 "Weapon1",
32 "Weapon2",
33 "BullRush",
34 "Grenade1",
35 "Grenade2",
36 "LookSpin",
37 "CurrentAbility",
38 "PreviousAbility",
39 "Ability1",
40 "Ability2",
41 "Ability3",
42 "Ability4",
43 }
44 var buttons []string
45 if input == 0 {
46 buttons = append(buttons, buttonList[0])
47 return buttons
48 }
49 for i := 1; i < 33; i++ {
50 if ReadBitState(input, i) {
51 buttons = append(buttons, buttonList[i])
52 }
53 }
54 return buttons
55}
56
57func ReadBitState(input int32, index int) bool {
58 value := input & (1 << index)
59 return value > 0
60}
61
62func ReadBitStateLSB(input byte, index int) (bool, error) {
63 if index < 0 && index > 7 {
64 return false, fmt.Errorf("IndexOutOfBounds for type byte")
65 }
66 value := input & (1 << index)
67 return (value > 0), nil
68}
69
70func Read32BitsAfterFirstBitInt32(input []byte, index int, step int) int32 {
71 binary := ""
72 binary += fmt.Sprintf("%08b", input[step])[8-index : 8]
73 binary += fmt.Sprintf("%08b", input[step-1])
74 binary += fmt.Sprintf("%08b", input[step-2])
75 binary += fmt.Sprintf("%08b", input[step-3])
76 binary += fmt.Sprintf("%08b", input[step-4])[:8-index]
77 output, err := strconv.ParseInt(binary, 2, 32)
78 CheckError(err)
79 return int32(output)
80
81}
82
83func Read32BitsAfterFirstBitFloat32(input []byte, index int, step int) float32 {
84 binary := ""
85 binary += fmt.Sprintf("%08b", input[step])[8-index : 8]
86 binary += fmt.Sprintf("%08b", input[step-1])
87 binary += fmt.Sprintf("%08b", input[step-2])
88 binary += fmt.Sprintf("%08b", input[step-3])
89 binary += fmt.Sprintf("%08b", input[step-4])[:8-index]
90 output, err := strconv.ParseUint(binary, 2, 32)
91 CheckError(err)
92 return math.Float32frombits(uint32(output))
93
94}