blob: 92cac707bb184de40bd2da13c5ec8493ba6979a7 (
plain) (
blame)
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
|
//go:build (amd64 || arm64 || riscv64) && !purego
package proto
import (
"unsafe"
"github.com/go-faster/errors"
)
// EncodeColumn encodes Bool rows to *Buffer.
func (c ColBool) EncodeColumn(b *Buffer) {
if len(c) == 0 {
return
}
offset := len(b.Buf)
b.Buf = append(b.Buf, make([]byte, len(c))...)
s := *(*slice)(unsafe.Pointer(&c)) // #nosec G103
src := *(*[]byte)(unsafe.Pointer(&s)) // #nosec G103
dst := b.Buf[offset:]
copy(dst, src)
}
// DecodeColumn decodes Bool rows from *Reader.
func (c *ColBool) DecodeColumn(r *Reader, rows int) error {
if rows == 0 {
return nil
}
*c = append(*c, make([]bool, rows)...)
s := *(*slice)(unsafe.Pointer(c)) // #nosec G103
dst := *(*[]byte)(unsafe.Pointer(&s)) // #nosec G103
if err := r.ReadFull(dst); err != nil {
return errors.Wrap(err, "read full")
}
return nil
}
|