module Rattletrap.Encode.Common
  ( putBitsLE
  )
where

import qualified Data.Binary.Bits.Put as BinaryBits
import qualified Data.Bits as Bits

putBitsLE :: Bits.Bits a => Int -> a -> BinaryBits.BitPut ()
putBitsLE :: Int -> a -> BitPut ()
putBitsLE Int
size a
x = (Int -> BitPut ()) -> [Int] -> BitPut ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Bool -> BitPut ()
BinaryBits.putBool (Bool -> BitPut ()) -> (Int -> Bool) -> Int -> BitPut ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
Bits.testBit a
x) [Int
0 .. Int
size Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]