column_uint32.go 614 B

1234567891011121314151617181920212223242526272829303132
  1. package data
  2. import (
  3. "encoding/binary"
  4. "fmt"
  5. "io"
  6. )
  7. type ColumnUint32 struct {
  8. }
  9. const SIZE_Uint32 = 4
  10. func (c *ColumnUint32) Read(buf []byte, readerAt io.ReaderAt, offset int64, i int64) uint32 {
  11. if n, err := readerAt.ReadAt(buf, offset+i*SIZE_Uint32); n == SIZE_Uint32 && err == nil {
  12. return binary.BigEndian.Uint32(buf)
  13. }
  14. return 0
  15. }
  16. func WriteUint32s(buf []byte, data []uint32) (err error) {
  17. off := 0
  18. size := len(data)
  19. if len(buf) < size<<2 {
  20. return fmt.Errorf("buf too small")
  21. }
  22. for _, dat := range data {
  23. binary.BigEndian.PutUint32(buf[off:], dat)
  24. off += SIZE_Uint32
  25. }
  26. return nil
  27. }