module Database.Perdure.AllocCopy (
AllocCopy(..),
allocCopyBits,
module Database.Perdure.WriteBits
) where
import Prelude ()
import Cgm.Prelude
import Cgm.Data.Word
import Cgm.Data.Len
import Database.Perdure.WriteBits
import Cgm.System.Endian
class Endian w => AllocCopy w where
allocCopyBitsSkip :: (BitSrc d, SrcDestState d ~ RealWorld) => Len w Word -> d -> d -> ST RealWorld (STPrimArray RealWorld Pinned w)
allocCopyBits :: (BitSrc d, SrcDestState d ~ RealWorld, AllocCopy w) => d -> d -> IO (PrimArray Pinned w)
allocCopyBits start end = stToIO $ allocCopyBitsSkip 0 start end >>= unsafeFreezeSTPrimArray
instance AllocCopy Word32 where
allocCopyBitsSkip skip start end = onWordConv
(apply wordConv1 <$> allocCopyBitsSkip (retract wordLenB skip) start end)
(error "allocCopyBitsSkip for Word32 not implemented")
instance AllocCopy Word64 where
allocCopyBitsSkip skip start end = onWordConv
(error "allocCopyBitsSkip for Word64 not implemented")
(apply wordConv1 <$> allocCopyBitsSkip (retract wordLenB skip) start end)
instance AllocCopy Word where
allocCopyBitsSkip skip start end = do
wBuf <- mkArray $ coarsenLen (addedBits end start) + skip
_ <- copyBits end start (aligned $ CWordSeq wBuf skip) >>= padIncompleteWord
return wBuf