-- | Receives a value. Runs a 'B.Get' monad to parse it
receiveGet :: (MonadIO m) => BinaryCom -> B.Get a -> m a
receiveGet (BinaryCom ref _ _) getAction = liftIO $ do
  inp <- readIORef ref
  let (val, inpRest, _) = B.runGetState getAction inp 0
  writeIORef ref inpRest
  return val

-- | A if-then-else, but with the condition as last argument
receiveGet :: (MonadIO m) => BinaryCom -> B.Get a -> m a
receiveGet (BinaryCom ref _ _) getAction = liftIO $ do
  inp <- readIORef ref
  let (val, inpRest, _) = B.runGetState getAction inp 0
  writeIORef ref inpRest
  return val

-- | A if-then-else, but with the condition as last argument
receiveGet (BinaryCom ref _ _) getAction = liftIO $ do
  inp <- readIORef ref
  let (val, inpRest, _) = B.runGetState getAction inp 0
  writeIORef ref inpRest
  return val

-- | A if-then-else, but with the condition as last argument