uint32.go 872 B

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