FedP2P/bencode/bytes.go

26 lines
416 B
Go
Raw Normal View History

2016-08-26 12:51:09 +08:00
package bencode
import (
"errors"
)
2016-08-26 12:51:09 +08:00
type Bytes []byte
var (
_ Unmarshaler = (*Bytes)(nil)
_ Marshaler = (*Bytes)(nil)
_ Marshaler = Bytes{}
2016-08-26 12:51:09 +08:00
)
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
2016-08-26 12:51:09 +08:00
}