-
Notifications
You must be signed in to change notification settings - Fork 66
/
error.go
48 lines (38 loc) · 1.05 KB
/
error.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
package vector
import (
"github.com/brimdata/zed"
"github.com/brimdata/zed/zcode"
)
type Error struct {
Typ zed.Type
Vals Any
Nulls *Bool
}
var _ Any = (*Error)(nil)
// XXX we shouldn't create empty fields... this was the old design, now
// we create the entire vector structure and page in leaves, offsets, etc on demand
func NewError(typ zed.Type, vals Any, nulls *Bool) *Error {
return &Error{Typ: typ, Vals: vals, Nulls: nulls}
}
func (e *Error) Type() zed.Type {
return e.Typ
}
func (e *Error) Len() uint32 {
return e.Vals.Len()
}
func (e *Error) Serialize(b *zcode.Builder, slot uint32) {
if e.Nulls != nil && e.Nulls.Value(slot) {
b.Append(nil)
return
}
e.Vals.Serialize(b, slot)
}
func NewStringError(zctx *zed.Context, msg string, len uint32) *Error {
vals := NewConst(zed.NewString(msg), len, nil)
return &Error{Typ: zctx.LookupTypeError(zed.TypeString), Vals: vals}
}
func NewMissing(zctx *zed.Context, len uint32) *Error {
missing := zctx.Missing()
vals := NewConst(missing, len, nil)
return &Error{Typ: missing.Type(), Vals: vals}
}