github.com/anacrolix/torrent@v1.61.0/bencode/bytes.go (about) 1 package bencode 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 type Bytes []byte 9 10 var ( 11 _ Unmarshaler = (*Bytes)(nil) 12 _ Marshaler = (*Bytes)(nil) 13 _ Marshaler = Bytes{} 14 ) 15 16 func (me *Bytes) UnmarshalBencode(b []byte) error { 17 *me = append([]byte(nil), b...) 18 return nil 19 } 20 21 func (me Bytes) MarshalBencode() ([]byte, error) { 22 if len(me) == 0 { 23 return nil, errors.New("marshalled Bytes should not be zero-length") 24 } 25 return me, nil 26 } 27 28 func (me Bytes) GoString() string { 29 return fmt.Sprintf("bencode.Bytes(%q)", []byte(me)) 30 }