-
Notifications
You must be signed in to change notification settings - Fork 2
/
tag.go
39 lines (29 loc) · 788 Bytes
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package types
import (
"github.com/hamba/avro/v2"
)
type Tag struct {
Name string `json:"name" avro:"name"`
Value string `json:"value" avro:"value"`
}
type Tags []Tag
var avroParser = avro.MustParse(`{"type": "array", "items": {"type": "record", "name": "Tag", "fields": [{"name": "name", "type": "string"}, {"name": "value", "type": "string"}]}}`)
func (self Tags) Marshal() ([]byte, error) {
if len(self) == 0 {
return make([]byte, 0), nil
}
return avro.Marshal(avroParser, self)
}
func (self Tags) Unmarshal(data []byte) error {
return avro.Unmarshal(avroParser, data, &self)
}
func (self Tags) Size() int {
if len(self) == 0 {
return 0
}
data, _ := self.Marshal()
return len(data)
}
func (self Tags) Append(tags []Tag) Tags {
return append(self, tags...)
}