-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathnet.go
More file actions
50 lines (40 loc) · 842 Bytes
/
net.go
File metadata and controls
50 lines (40 loc) · 842 Bytes
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
package vector
import (
"net/netip"
"github.com/brimdata/super"
"github.com/brimdata/super/scode"
)
type Net struct {
Values []netip.Prefix
}
var _ Any = (*Net)(nil)
func NewNet(values []netip.Prefix) *Net {
return &Net{values}
}
func (*Net) Kind() Kind {
return KindNet
}
func (n *Net) Type() super.Type {
return super.TypeNet
}
func (n *Net) Len() uint32 {
return uint32(len(n.Values))
}
func (n *Net) Serialize(b *scode.Builder, slot uint32) {
b.Append(super.EncodeNet(n.Values[slot]))
}
func NetValue(val Any, slot uint32) netip.Prefix {
switch val := val.(type) {
case *Net:
return val.Values[slot]
case *Const:
return NetValue(val.Any, 0)
case *Dict:
slot = uint32(val.Index[slot])
return val.Any.(*Net).Values[slot]
case *View:
slot = val.Index[slot]
return NetValue(val.Any, slot)
}
panic(val)
}