| commit | d522839ac797fc43269dae6a04a1f8be475a915d | [log] [tgz] |
|---|---|---|
| author | Alex Grin <[email protected]> | Thu Mar 08 00:08:55 2018 |
| committer | Jeff <[email protected]> | Thu Mar 08 17:45:30 2018 |
| tree | 1975880ad5a9edc30571eafaee94f2f98965fb63 | |
| parent | 1f43a06f6eb53936bc028b38cdd060f0b5629c6c [diff] |
Fix marshaler detection
Here's a reproducible case:
```
type T []byte
func (x T) MarshalBencode() ([]byte, error) {
fmt.Println("THIS GOT CALLED")
return []byte("x"), nil
}
encoded, err := bencode.EncodeBytes([]interface{}{
T("something"),
})
fmt.Println(encoded)
```
Notice that MarshalBencode() is not called when it should be.
The problem stems from NumMethod() returning 0 for the interface, even though the `vi.(Marshaler)` cast would succeed. Removing that if check fixed the issue for me.
Bencode is a library for encoding/decoding bencoded data into Go data structures. The api is designed to be similar to the JSON api in the Go standard library.
Documentation at http://godoc.org/github.com/zeebo/bencode