github.com/anacrolix/torrent@v1.61.0/bencode/tags.go (about)

     1  package bencode
     2  
     3  import (
     4  	"reflect"
     5  	"strings"
     6  )
     7  
     8  func getTag(st reflect.StructTag) tag {
     9  	return parseTag(st.Get("bencode"))
    10  }
    11  
    12  type tag []string
    13  
    14  func parseTag(tagStr string) tag {
    15  	return strings.Split(tagStr, ",")
    16  }
    17  
    18  func (me tag) Ignore() bool {
    19  	return me[0] == "-"
    20  }
    21  
    22  func (me tag) Key() string {
    23  	return me[0]
    24  }
    25  
    26  func (me tag) HasOpt(opt string) bool {
    27  	if len(me) < 1 {
    28  		return false
    29  	}
    30  	for _, s := range me[1:] {
    31  		if s == opt {
    32  			return true
    33  		}
    34  	}
    35  	return false
    36  }
    37  
    38  func (me tag) OmitEmpty() bool {
    39  	return me.HasOpt("omitempty")
    40  }
    41  
    42  func (me tag) IgnoreUnmarshalTypeError() bool {
    43  	return me.HasOpt("ignore_unmarshal_type_error")
    44  }