aboutsummaryrefslogtreecommitdiff
path: root/bencode/bencode.go
diff options
context:
space:
mode:
Diffstat (limited to 'bencode/bencode.go')
-rw-r--r--bencode/bencode.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/bencode/bencode.go b/bencode/bencode.go
index f8e72ec..6b0913d 100644
--- a/bencode/bencode.go
+++ b/bencode/bencode.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"reflect"
+ "strconv"
"strings"
"time"
)
@@ -123,3 +124,27 @@ func Unmarshal(data []byte, v interface{}) error {
}
return nil
}
+
+func unmarshalString(data []byte) string {
+ if i := bytes.IndexByte(data, ':'); i != -1 {
+ len, err := strconv.Atoi(string(data[:i]))
+ if err != nil {
+ return ""
+ }
+ return string(data[i+1 : i+1+len])
+ }
+ return ""
+}
+
+func unmarshalInt(data []byte) int {
+ pos := 0
+ if data[pos] == 'i' {
+ pos++
+ }
+ end := bytes.IndexByte(data, 'e')
+ i, err := strconv.Atoi(string(data[pos:end]))
+ if err != nil {
+ return 0
+ }
+ return i
+}