1package msgpack 2 3import ( 4 "strings" 5) 6 7type tagOptions string 8 9func (o tagOptions) Get(name string) (string, bool) { 10 s := string(o) 11 for len(s) > 0 { 12 var next string 13 idx := strings.IndexByte(s, ',') 14 if idx >= 0 { 15 s, next = s[:idx], s[idx+1:] 16 } 17 if strings.HasPrefix(s, name) { 18 return s[len(name):], true 19 } 20 s = next 21 } 22 return "", false 23} 24 25func (o tagOptions) Contains(name string) bool { 26 _, ok := o.Get(name) 27 return ok 28} 29 30func parseTag(tag string) (string, tagOptions) { 31 if idx := strings.IndexByte(tag, ','); idx != -1 { 32 name := tag[:idx] 33 if strings.IndexByte(name, ':') == -1 { 34 return name, tagOptions(tag[idx+1:]) 35 } 36 } 37 38 if strings.IndexByte(tag, ':') == -1 { 39 return tag, "" 40 } 41 return "", tagOptions(tag) 42} 43