-
Notifications
You must be signed in to change notification settings - Fork 67
/
net.go
68 lines (53 loc) · 1.23 KB
/
net.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package vector
import (
"net/netip"
"github.com/brimdata/zed"
"github.com/brimdata/zed/zcode"
)
type Net struct {
Values []netip.Prefix
Nulls *Bool
}
var _ Any = (*Net)(nil)
func NewNet(values []netip.Prefix, nulls *Bool) *Net {
return &Net{Values: values, Nulls: nulls}
}
func (n *Net) Type() zed.Type {
return zed.TypeNet
}
func (n *Net) Len() uint32 {
return uint32(len(n.Values))
}
func (n *Net) Serialize(b *zcode.Builder, slot uint32) {
if n.Nulls != nil && n.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(zed.EncodeNet(n.Values[slot]))
}
}
type DictNet struct {
Tags []byte
Values []netip.Prefix
Counts []uint32
Nulls *Bool
}
var _ Any = (*DictNet)(nil)
func NewDictNet(tags []byte, values []netip.Prefix, counts []uint32, nulls *Bool) *DictNet {
return &DictNet{Tags: tags, Values: values, Counts: counts, Nulls: nulls}
}
func (d *DictNet) Type() zed.Type {
return zed.TypeNet
}
func (d *DictNet) Len() uint32 {
return uint32(len(d.Tags))
}
func (d *DictNet) Value(slot uint32) netip.Prefix {
return d.Values[d.Tags[slot]]
}
func (d *DictNet) Serialize(b *zcode.Builder, slot uint32) {
if d.Nulls != nil && d.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(zed.EncodeNet(d.Value(slot)))
}
}