aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/ch-go/proto/col_raw.go
blob: ba655f46f00cbf6db5e8b1d8d7d435bdfe93696d (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
package proto

import "github.com/go-faster/errors"

// ColRaw is Column that performs zero decoding or encoding.
// T, Size are required.
//
// TODO: support strings and T, Size inference.
//
// Useful for copying from one source to another.
type ColRaw struct {
	T    ColumnType // type of column
	Size int        // size of single value

	Data  []byte // raw value of column
	Count int    // count of rows
}

func (c ColRaw) Type() ColumnType       { return c.T }
func (c ColRaw) Rows() int              { return c.Count }
func (c ColRaw) EncodeColumn(b *Buffer) { b.Buf = append(b.Buf, c.Data...) }

func (c *ColRaw) DecodeColumn(r *Reader, rows int) error {
	c.Count = rows
	c.Data = append(c.Data[:0], make([]byte, c.Size*rows)...)
	if err := r.ReadFull(c.Data); err != nil {
		return errors.Wrap(err, "read full")
	}
	return nil
}

func (c *ColRaw) Reset() {
	c.Count = 0
	c.Data = c.Data[:0]
}