github.com/parquet-go/parquet-go@v0.20.0/internal/bitpack/unpack_int32_purego.go (about)

     1  //go:build purego || !amd64
     2  
     3  package bitpack
     4  
     5  import (
     6  	"github.com/parquet-go/parquet-go/internal/unsafecast"
     7  )
     8  
     9  func unpackInt32(dst []int32, src []byte, bitWidth uint) {
    10  	bits := unsafecast.BytesToUint32(src)
    11  	bitMask := uint32(1<<bitWidth) - 1
    12  	bitOffset := uint(0)
    13  
    14  	for n := range dst {
    15  		i := bitOffset / 32
    16  		j := bitOffset % 32
    17  		d := (bits[i] & (bitMask << j)) >> j
    18  		if j+bitWidth > 32 {
    19  			k := 32 - j
    20  			d |= (bits[i+1] & (bitMask >> k)) << k
    21  		}
    22  		dst[n] = int32(d)
    23  		bitOffset += bitWidth
    24  	}
    25  }