module Rattletrap.Decode.List
  ( decodeList
  )
where

import Rattletrap.Decode.Common
import Rattletrap.Decode.Word32le
import Rattletrap.Type.List
import Rattletrap.Type.Word32le

import qualified Control.Monad as Monad

decodeList :: Decode a -> Decode (List a)
decodeList :: Decode a -> Decode (List a)
decodeList Decode a
decodeElement = do
  Word32le
size <- Decode Word32le
decodeWord32le
  [a] -> List a
forall a. [a] -> List a
List ([a] -> List a) -> Get [a] -> Decode (List a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Decode a -> Get [a]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
Monad.replicateM (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32le -> Word32
word32leValue Word32le
size)) Decode a
decodeElement