aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint8.go
blob: 8af493e7a0020dafed847eddc04a268c88ac48ce (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
37
38
39
40
41
42
43
44
45
46
47
package column

import (
	"github.com/ClickHouse/clickhouse-go/lib/binary"
)

type UInt8 struct{ base }

func (UInt8) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) {
	v, err := decoder.UInt8()
	if err != nil {
		return uint8(0), err
	}
	return v, nil
}

func (u *UInt8) Write(encoder *binary.Encoder, v interface{}) error {
	switch v := v.(type) {
	case bool:
		return encoder.Bool(v)
	case uint8:
		return encoder.UInt8(v)
	case int64:
		return encoder.UInt8(uint8(v))
	case uint64:
		return encoder.UInt8(uint8(v))
	case int:
		return encoder.UInt8(uint8(v))

	// this relies on Nullable never sending nil values through
	case *bool:
		return encoder.Bool(*v)
	case *uint8:
		return encoder.UInt8(*v)
	case *int64:
		return encoder.UInt8(uint8(*v))
	case *uint64:
		return encoder.UInt8(uint8(*v))
	case *int:
		return encoder.UInt8(uint8(*v))
	}

	return &ErrUnexpectedType{
		T:      v,
		Column: u,
	}
}