10 var sanitizer = strings.NewReplacer(
16 func NewItemMeta(fields []Field) ItemMeta {
21 b := new(strings.Builder)
23 for _, f := range fields {
24 sanitizer.WriteString(b, f.Name)
26 sanitizer.WriteString(b, f.Value)
29 return ItemMeta(b.String())
32 func (m ItemMeta) Fields() []Field {
34 if len(m) > 0 && m[0] == 1 {
36 eat := func(stop byte) string {
37 if i := strings.IndexByte(string(m), stop); i != -1 {
50 f = append(f, Field{eat(2), eat(3)})
55 return []Field{{"", string(m)}}
58 func (m ItemMeta) Field(name string) (s string, ok bool) {
59 for _, f := range m.Fields() {
67 func (m *ItemMeta) SetField(name, value string) {
69 for _, f := range m.Fields() {
71 fields = append(fields, f)
74 fields = append(fields, Field{name, value})
75 *m = NewItemMeta(fields)
78 func (m ItemMeta) ToolCaps() (ToolCaps, bool) {
79 f, ok := m.Field("tool_capabilities")
81 return ToolCaps{}, false
85 if err := json.Unmarshal([]byte(f), &tc); err != nil {
91 func (m *ItemMeta) SetToolCaps(tc ToolCaps) {
92 b, err := tc.MarshalJSON()
97 m.SetField("tool_capabilities", string(b))