aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/clickhouse-go/lib/column/float32.go
blob: 477a6a1a3927877bff84e0a2a0d6d3aeb1bad638 (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 column

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

type Float32 struct{ base }

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

func (float *Float32) Write(encoder *binary.Encoder, v interface{}) error {
	switch v := v.(type) {
	case float32:
		return encoder.Float32(v)
	case float64:
		return encoder.Float32(float32(v))

	// this relies on Nullable never sending nil values through
	case *float32:
		return encoder.Float32(*v)
	case *float64:
		return encoder.Float32(float32(*v))
	}

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