No description
  • Go 98.4%
  • Makefile 1.6%
Find a file
2020-07-31 13:44:55 +10:00
testdata Extract source from existing project 2018-04-02 00:10:05 +10:00
.gitignore Update to Go module 2019-03-14 12:41:50 +11:00
comparison_test.go Extract source from existing project 2018-04-02 00:10:05 +10:00
decode.go Clean up some of the offset fiddling 2018-04-02 00:10:12 +10:00
decode_test.go Clean up some of the offset fiddling 2018-04-02 00:10:12 +10:00
encode.go Add []byte to string encoding 2018-04-02 00:10:12 +10:00
encode_test.go Extract source from existing project 2018-04-02 00:10:05 +10:00
go.mod Clean up makefile, readme and drone stuff 2019-10-29 21:46:35 +11:00
go.sum Update to Go module 2019-03-14 12:41:50 +11:00
LICENSE Extract source from existing project 2018-04-02 00:10:05 +10:00
Makefile Clean up makefile 2020-07-31 13:44:55 +10:00
README.md Update benchmarks 2019-10-29 22:04:24 +11:00

go-bencode

A Go library for handling data in the bencode format. This is the format used by the Mainline DHT and BitTorrent protocols.

Usage

All encoded data objects are []byte. This is the format returned by many network libraries such as UDPConn.Read() etc.

import bencode "src.userspace.com.au/go-bencode"

var i interface{}
var packet []byte
var str string

i, err = bencode.Decode(packet)

// Or if you know the type
str, err = bencode.DecodeString(packet)

// Encoding a string, int, slice or map
packet, err = bencode.Encode(str)

Benchmarks

Just for fun and comparison (go v1.13):

go test -bench=.
goos: freebsd
goarch: amd64
pkg: src.userspace.com.au/go-bencode
BenchmarkFelix-4                  140659              8518 ns/op
BenchmarkMarkSamman-4              72080             16857 ns/op
BenchmarkJackpal-4                 70902             17194 ns/op
BenchmarkDecodeWithString-4      6856792               183 ns/op
BenchmarkDecodeString-4         10423938               130 ns/op
BenchmarkDecodeWithInt-4         8644882               146 ns/op
BenchmarkDecodeInt-4            11680635               107 ns/op
BenchmarkDecodeWithList-4        2046406               527 ns/op
BenchmarkDecodeList-4            2494192               464 ns/op
BenchmarkDecodeWithDict-4        2505790               479 ns/op
BenchmarkDecodeDict-4            2674564               480 ns/op
PASS
ok      src.userspace.com.au/go-bencode 17.455s