-
Notifications
You must be signed in to change notification settings - Fork 25
/
example_test.go
67 lines (58 loc) · 1 KB
/
example_test.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
56
57
58
59
60
61
62
63
64
65
66
67
package bencode
import (
"fmt"
"io"
)
var (
data string
r io.Reader
w io.Writer
)
func ExampleDecodeString() {
var torrent interface{}
if err := DecodeString(data, &torrent); err != nil {
panic(err)
}
}
func ExampleEncodeString() {
var torrent interface{}
data, err := EncodeString(torrent)
if err != nil {
panic(err)
}
fmt.Println(data)
}
func ExampleDecodeBytes() {
var torrent interface{}
if err := DecodeBytes([]byte(data), &torrent); err != nil {
panic(err)
}
}
func ExampleEncodeBytes() {
var torrent interface{}
data, err := EncodeBytes(torrent)
if err != nil {
panic(err)
}
fmt.Println(data)
}
func ExampleEncoder_Encode() {
var x struct {
Foo string
Bar []string `bencode:"name"`
}
enc := NewEncoder(w)
if err := enc.Encode(x); err != nil {
panic(err)
}
}
func ExampleDecoder_Decode() {
dec := NewDecoder(r)
var torrent struct {
Announce string
List [][]string `bencode:"announce-list"`
}
if err := dec.Decode(&torrent); err != nil {
panic(err)
}
}