-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (42 loc) · 995 Bytes
/
main.go
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
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
gobencode "joshua/green/bencode"
"os"
)
type Package struct {
Name string
Date int
Peers []string
}
func main() {
FileDecodeExample()
StringDecodeExample()
EncodeExample1()
EncodeExample2()
}
func FileDecodeExample() {
fmt.Println("\n\n\t\tFileDecodeExample")
res := gobencode.DecodeFile("sample.torrent")
fmt.Println(res)
}
func StringDecodeExample() {
fmt.Println("\n\n\t\tStringDecodeExample")
res := gobencode.DecodeString("l5:hello5:worldi12345ed6:animal3:cat4:typei1eee")
fmt.Println(res)
}
func EncodeExample1() {
fmt.Println("\n\n\t\tEncodeExample1")
e := gobencode.NewEncoder(os.Stdout)
list := gobencode.DecodeString("l5:hello5:worldi12345ed6:animal3:cat4:typei1eee")
e.Encode(list)
}
func EncodeExample2() {
fmt.Println("\n\n\t\tEncodeExample2")
e := gobencode.NewEncoder(os.Stdout)
e.Encode(1234)
fmt.Println()
e.Encode([]string{"hello", "world"})
fmt.Println()
e.Encode(map[string]int{"a": 1, "b": 2, "c": 3})
}