-
Notifications
You must be signed in to change notification settings - Fork 66
/
ip.go
68 lines (53 loc) · 1.2 KB
/
ip.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 IP struct {
Values []netip.Addr
Nulls *Bool
}
var _ Any = (*IP)(nil)
func NewIP(values []netip.Addr, nulls *Bool) *IP {
return &IP{Values: values, Nulls: nulls}
}
func (i *IP) Type() zed.Type {
return zed.TypeIP
}
func (i *IP) Len() uint32 {
return uint32(len(i.Values))
}
func (i *IP) Serialize(b *zcode.Builder, slot uint32) {
if i.Nulls != nil && i.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(zed.EncodeIP(i.Values[slot]))
}
}
type DictIP struct {
Tags []byte
Values []netip.Addr
Counts []uint32
Nulls *Bool
}
var _ Any = (*DictIP)(nil)
func NewDictIP(tags []byte, values []netip.Addr, counts []uint32, nulls *Bool) *DictIP {
return &DictIP{Tags: tags, Values: values, Counts: counts, Nulls: nulls}
}
func (d *DictIP) Type() zed.Type {
return zed.TypeIP
}
func (d *DictIP) Len() uint32 {
return uint32(len(d.Tags))
}
func (d *DictIP) Value(slot uint32) netip.Addr {
return d.Values[d.Tags[slot]]
}
func (d *DictIP) Serialize(b *zcode.Builder, slot uint32) {
if d.Nulls != nil && d.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(zed.EncodeIP(d.Value(slot)))
}
}