-- | /DEPRECATED/ - This module is deprecated and used in Byron era exclusively. For newer
-- implementation of this functionality use `Cardano.Ledger.Binary.Decoding.DecCBOR.dropCBOR`
--
-- A 'Dropper s' is a 'Decoder s ()', that is a decoder that returns nothing
--
--   We use 'Dropper's when we don't care about the result of decoding, for
--   example when we have deprecated some part of the serialised blockchain, but
--   still need to decode old blocks.
module Cardano.Ledger.Binary.Decoding.Drop (
  Dropper,
  dropBytes,
  dropInt32,
  dropList,
  dropMap,
  dropSet,
  dropTuple,
  dropTriple,
  dropWord8,
  dropWord64,
)
where

import Cardano.Ledger.Binary.Decoding.Decoder
import Control.Monad (replicateM_)
import Data.Functor (void)

type Dropper s = Decoder s ()

dropBytes :: Dropper s
dropBytes :: forall s. Dropper s
dropBytes = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall s. Decoder s ByteString
decodeBytes

dropInt32 :: Dropper s
dropInt32 :: forall s. Dropper s
dropInt32 = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall s. Decoder s Int32
decodeInt32

-- | Drop a list of values using the supplied `Dropper` for each element
dropList :: Dropper s -> Dropper s
dropList :: forall s. Dropper s -> Dropper s
dropList Dropper s
dropElems = do
  forall s. Dropper s
decodeListLenIndef
  forall r a b s.
(r -> a -> r) -> r -> (r -> b) -> Decoder s a -> Decoder s b
decodeSequenceLenIndef forall a b. a -> b -> a
const () forall a. a -> a
id Dropper s
dropElems

dropMap :: Dropper s -> Dropper s -> Dropper s
dropMap :: forall s. Dropper s -> Dropper s -> Dropper s
dropMap Dropper s
dropKey Dropper s
dropValue = do
  Int
n <- forall s. Decoder s Int
decodeMapLen
  forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
n forall a b. (a -> b) -> a -> b
$ Dropper s
dropKey forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Dropper s
dropValue

dropSet :: Dropper s -> Dropper s
dropSet :: forall s. Dropper s -> Dropper s
dropSet Dropper s
dropElem = do
  forall (f :: * -> *) a. Functor f => f a -> f ()
void forall s. Decoder s Word
decodeTag
  Int
n <- forall s. Decoder s Int
decodeListLen
  forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
n Dropper s
dropElem

dropTuple :: Dropper s -> Dropper s -> Dropper s
dropTuple :: forall s. Dropper s -> Dropper s -> Dropper s
dropTuple Dropper s
dropA Dropper s
dropB = do
  forall s. Int -> Decoder s ()
decodeListLenOf Int
2
  Dropper s
dropA
  Dropper s
dropB

dropTriple :: Dropper s -> Dropper s -> Dropper s -> Dropper s
dropTriple :: forall s. Dropper s -> Dropper s -> Dropper s -> Dropper s
dropTriple Dropper s
dropA Dropper s
dropB Dropper s
dropC = do
  forall s. Int -> Decoder s ()
decodeListLenOf Int
3
  Dropper s
dropA
  Dropper s
dropB
  Dropper s
dropC

dropWord8 :: Dropper s
dropWord8 :: forall s. Dropper s
dropWord8 = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall s. Decoder s Word8
decodeWord8

dropWord64 :: Dropper s
dropWord64 :: forall s. Dropper s
dropWord64 = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall s. Decoder s Word64
decodeWord64