float32.go 703 B

1234567891011121314151617181920212223242526272829303132333435
  1. package column
  2. import (
  3. "github.com/ClickHouse/clickhouse-go/lib/binary"
  4. )
  5. type Float32 struct{ base }
  6. func (Float32) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) {
  7. v, err := decoder.Float32()
  8. if err != nil {
  9. return float32(0), err
  10. }
  11. return v, nil
  12. }
  13. func (float *Float32) Write(encoder *binary.Encoder, v interface{}) error {
  14. switch v := v.(type) {
  15. case float32:
  16. return encoder.Float32(v)
  17. case float64:
  18. return encoder.Float32(float32(v))
  19. // this relies on Nullable never sending nil values through
  20. case *float32:
  21. return encoder.Float32(*v)
  22. case *float64:
  23. return encoder.Float32(float32(*v))
  24. }
  25. return &ErrUnexpectedType{
  26. T: v,
  27. Column: float,
  28. }
  29. }