-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.go
More file actions
39 lines (31 loc) · 743 Bytes
/
buffer.go
File metadata and controls
39 lines (31 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package utils
import "strings"
const (
hextable = "0123456789abcdef"
)
type Buffer []byte
func NewBuffer() Buffer {
return make([]byte,0)
}
func (b Buffer) Length() int{
return len(b) // the unint is byte
}
func (b Buffer) String() string {
str := make([]byte,b.Length() << 1)
j := 0
for _,item := range b {
str[j] = hextable[item>>4]
str[j+1] = hextable[item&0x0f]
j += 2
}
return string(str)
}
func (b Buffer) Load(data string) Buffer{
for i:= 0;i < len(data);i+=2 {
cache := 0x00
cache = strings.Index(hextable,string(data[i])) << 4
cache = cache | strings.Index(hextable,string(data[i+1]))
b = append(b, byte(cache))
}
return b
}