github.com/anacrolix/torrent@v1.61.0/metainfo/urllist.go (about)

     1  package metainfo
     2  
     3  import (
     4  	"github.com/anacrolix/torrent/bencode"
     5  )
     6  
     7  type UrlList []string
     8  
     9  var _ bencode.Unmarshaler = (*UrlList)(nil)
    10  
    11  func (me *UrlList) UnmarshalBencode(b []byte) error {
    12  	if len(b) == 0 {
    13  		return nil
    14  	}
    15  	if b[0] == 'l' {
    16  		var l []string
    17  		err := bencode.Unmarshal(b, &l)
    18  		*me = l
    19  		return err
    20  	}
    21  	var s string
    22  	err := bencode.Unmarshal(b, &s)
    23  	*me = []string{s}
    24  	return err
    25  }