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