-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbdecode_test.go
More file actions
46 lines (42 loc) · 880 Bytes
/
bdecode_test.go
File metadata and controls
46 lines (42 loc) · 880 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
40
41
42
43
44
45
46
package bencode_test
import (
"fmt"
"testing"
"github.com/h1zzz/bencode-go"
)
func TestDecode(t *testing.T) {
data := []byte("d4:porti6881e1:ad6:target20:mnopqrstuvwxyz1234562:id20:abcdefghij0123456789e1:y1:e1:t2:aa1:eli201e23:A Generic Error Ocurredee")
r, err := bencode.Decode(data)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%#v\n", r)
}
func TestEncode(t *testing.T) {
msg := map[string]interface{}{
"a": map[string]interface{}{
"id": "abcdefghij0123456789",
"target": "mnopqrstuvwxyz123456",
},
"e": []interface{}{
201,
"A Generic Error Ocurred",
},
"port": 6881,
"t": "aa",
"y": "e",
}
data, err := bencode.Encode(msg)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s\n", string(data))
r, err := bencode.Decode(data)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%#v\n", r)
}