-
Notifications
You must be signed in to change notification settings - Fork 67
/
type.go
73 lines (58 loc) · 1.47 KB
/
type.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
69
70
71
72
73
package vector
import (
"github.com/brimdata/zed"
"github.com/brimdata/zed/zcode"
)
type TypeValue struct {
Offsets []uint32
Bytes []byte
Nulls *Bool
}
var _ Any = (*TypeValue)(nil)
func NewTypeValue(offs []uint32, bytes []byte, nulls *Bool) *TypeValue {
return &TypeValue{Offsets: offs, Bytes: bytes, Nulls: nulls}
}
func (t *TypeValue) Type() zed.Type {
return zed.TypeType
}
func (t *TypeValue) Len() uint32 {
return uint32(len(t.Offsets) - 1)
}
func (t *TypeValue) Value(slot uint32) []byte {
return t.Bytes[t.Offsets[slot]:t.Offsets[slot+1]]
}
func (t *TypeValue) Serialize(b *zcode.Builder, slot uint32) {
if t.Nulls != nil && t.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(t.Value(slot))
}
}
type DictTypeValue struct {
Tags []byte
Offs []uint32
Bytes []byte
Counts []uint32
Nulls *Bool
}
var _ Any = (*DictTypeValue)(nil)
func NewDictTypeValue(tags []byte, offs []uint32, bytes []byte, counts []uint32, nulls *Bool) *DictTypeValue {
return &DictTypeValue{Tags: tags, Offs: offs, Bytes: bytes, Counts: counts, Nulls: nulls}
}
func (d *DictTypeValue) Type() zed.Type {
return zed.TypeType
}
func (d *DictTypeValue) Len() uint32 {
return uint32(len(d.Tags))
}
func (d *DictTypeValue) Value(slot uint32) []byte {
tag := d.Tags[slot]
return d.Bytes[d.Offs[tag]:d.Offs[tag+1]]
}
func (d *DictTypeValue) Serialize(b *zcode.Builder, slot uint32) {
if d.Nulls != nil && d.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(d.Value(slot))
}
}