-
Notifications
You must be signed in to change notification settings - Fork 67
/
string.go
73 lines (58 loc) · 1.48 KB
/
string.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 String struct {
Offsets []uint32
Bytes []byte
Nulls *Bool
}
var _ Any = (*String)(nil)
func NewString(offsets []uint32, bytes []byte, nulls *Bool) *String {
return &String{Offsets: offsets, Bytes: bytes, Nulls: nulls}
}
func (s *String) Type() zed.Type {
return zed.TypeString
}
func (s *String) Len() uint32 {
return uint32(len(s.Offsets) - 1)
}
func (s *String) Value(slot uint32) string {
return string(s.Bytes[s.Offsets[slot]:s.Offsets[slot+1]])
}
func (s *String) Serialize(b *zcode.Builder, slot uint32) {
if s.Nulls != nil && s.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(zed.EncodeString(s.Value(slot)))
}
}
type DictString struct {
Tags []byte
Offs []uint32
Bytes []byte
Counts []uint32
Nulls *Bool
}
var _ Any = (*DictString)(nil)
func NewDictString(tags []byte, offs []uint32, bytes []byte, counts []uint32, nulls *Bool) *DictString {
return &DictString{Tags: tags, Offs: offs, Bytes: bytes, Counts: counts, Nulls: nulls}
}
func (d *DictString) Type() zed.Type {
return zed.TypeString
}
func (d *DictString) Len() uint32 {
return uint32(len(d.Tags))
}
func (d *DictString) Value(slot uint32) string {
tag := d.Tags[slot]
return string(d.Bytes[d.Offs[tag]:d.Offs[tag+1]])
}
func (d *DictString) Serialize(b *zcode.Builder, slot uint32) {
if d.Nulls != nil && d.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(zed.EncodeString(d.Value(slot)))
}
}