zed
zed copied to clipboard
Values can exist with len 0 but non-nil base.
For example:
package main
import (
"bytes"
"fmt"
"github.com/brimdata/zed"
"github.com/brimdata/zed/zbuf"
"github.com/brimdata/zed/zio"
"github.com/brimdata/zed/zio/zngio"
//"github.com/brimdata/zed/zcode"
//"github.com/brimdata/zed/zson"
)
func main() {
bytesReader := bytes.NewReader([]byte("\x14\x00\x1b\x01\x100"))
context := zed.NewContext()
reader := zngio.NewReader(context, bytesReader)
var a zbuf.Array
if zio.Copy(&a, reader) != nil {
panic("")
}
values := a.Values()
fmt.Printf("%v\n", values[0])
value := zed.NewValue(zed.TypeNet, []byte{})
fmt.Printf("%v\n", *value)
}
The culprit in the first case is:
https://github.com/brimdata/zed/blob/82786cf9030fd1bfce0cd560b6b550f28c934898//zio/zngio/scanner.go#L308
If you try to eg convert these values to zson then it blows up at:
https://github.com/brimdata/zed/blob/82786cf9030fd1bfce0cd560b6b550f28c934898//primitive.go#L344
Not sure what the preferred fix is here. NewValue could detect zero-length slices. decodeValue could not return zero-length slices. zson could be more robust to zero-length slices. ¯_(ツ)_/¯