module Network.Haskoin.Protocol.Inv ( Inv(..) ) where
import Control.Monad (replicateM, forM_)
import Control.Applicative ((<$>))
import Data.Binary (Binary, get, put)
import Network.Haskoin.Protocol.InvVector
import Network.Haskoin.Protocol.VarInt
data Inv =
Inv {
invList :: ![InvVector]
} deriving (Eq, Show, Read)
instance Binary Inv where
get = Inv <$> (repList =<< get)
where
repList (VarInt c) = replicateM (fromIntegral c) get
put (Inv xs) = do
put $ VarInt $ fromIntegral $ length xs
forM_ xs put