-
Notifications
You must be signed in to change notification settings - Fork 67
/
const.go
58 lines (45 loc) · 993 Bytes
/
const.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
package vector
import (
"github.com/brimdata/zed"
"github.com/brimdata/zed/runtime/sam/expr/coerce"
"github.com/brimdata/zed/zcode"
)
type Const struct {
val zed.Value
len uint32
Nulls *Bool
}
var _ Any = (*Const)(nil)
func NewConst(val zed.Value, len uint32, nulls *Bool) *Const {
return &Const{val: val, len: len, Nulls: nulls}
}
func (c *Const) Type() zed.Type {
return c.val.Type()
}
func (c *Const) Len() uint32 {
return c.len
}
func (*Const) Ref() {}
func (*Const) Unref() {}
func (c *Const) Length() int {
return int(c.len)
}
func (c *Const) Value() zed.Value {
return c.val
}
func (c *Const) Serialize(b *zcode.Builder, slot uint32) {
if c.Nulls != nil && c.Nulls.Value(slot) {
b.Append(nil)
} else {
b.Append(c.val.Bytes())
}
}
func (c *Const) AsFloat() (float64, bool) {
return coerce.ToFloat(c.val)
}
func (c *Const) AsInt() (int64, bool) {
return coerce.ToInt(c.val)
}
func (c *Const) AsUint() (uint64, bool) {
return coerce.ToUint(c.val)
}