status-go/vendor/github.com/anacrolix/torrent/bencode/bytes.go

26 lines
416 B
Go
Raw Normal View History

2022-03-10 09:44:48 +00:00
package bencode
import (
"errors"
)
type Bytes []byte
var (
_ Unmarshaler = (*Bytes)(nil)
_ Marshaler = (*Bytes)(nil)
_ Marshaler = Bytes{}
)
func (me *Bytes) UnmarshalBencode(b []byte) error {
*me = append([]byte(nil), b...)
return nil
}
func (me Bytes) MarshalBencode() ([]byte, error) {
if len(me) == 0 {
return nil, errors.New("marshalled Bytes should not be zero-length")
}
return me, nil
}