{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving         #-}

module Ouroboros.Network.Protocol.BlockFetch.Codec.CDDL where

import Codec.CBOR.Read qualified as CBOR
import Codec.Serialise (Serialise)
import Codec.Serialise.Class qualified as Serialise
import Control.DeepSeq
import Data.ByteString.Lazy qualified as BL
import GHC.Generics
import Network.TypedProtocol.Codec
import Ouroboros.Network.Protocol.BlockFetch.Codec
import Ouroboros.Network.Protocol.BlockFetch.Type
import Test.Data.CDDL
import Test.QuickCheck

newtype Block = Block Any
  deriving (Block -> Block -> Bool
(Block -> Block -> Bool) -> (Block -> Block -> Bool) -> Eq Block
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Block -> Block -> Bool
== :: Block -> Block -> Bool
$c/= :: Block -> Block -> Bool
/= :: Block -> Block -> Bool
Eq, Int -> Block -> ShowS
[Block] -> ShowS
Block -> String
(Int -> Block -> ShowS)
-> (Block -> String) -> ([Block] -> ShowS) -> Show Block
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Block -> ShowS
showsPrec :: Int -> Block -> ShowS
$cshow :: Block -> String
show :: Block -> String
$cshowList :: [Block] -> ShowS
showList :: [Block] -> ShowS
Show, Gen Block
Gen Block -> (Block -> [Block]) -> Arbitrary Block
Block -> [Block]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen Block
arbitrary :: Gen Block
$cshrink :: Block -> [Block]
shrink :: Block -> [Block]
Arbitrary, [Block] -> Encoding
Block -> Encoding
(Block -> Encoding)
-> (forall s. Decoder s Block)
-> ([Block] -> Encoding)
-> (forall s. Decoder s [Block])
-> Serialise Block
forall s. Decoder s [Block]
forall s. Decoder s Block
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
$cencode :: Block -> Encoding
encode :: Block -> Encoding
$cdecode :: forall s. Decoder s Block
decode :: forall s. Decoder s Block
$cencodeList :: [Block] -> Encoding
encodeList :: [Block] -> Encoding
$cdecodeList :: forall s. Decoder s [Block]
decodeList :: forall s. Decoder s [Block]
Serialise, (forall x. Block -> Rep Block x)
-> (forall x. Rep Block x -> Block) -> Generic Block
forall x. Rep Block x -> Block
forall x. Block -> Rep Block x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Block -> Rep Block x
from :: forall x. Block -> Rep Block x
$cto :: forall x. Rep Block x -> Block
to :: forall x. Rep Block x -> Block
Generic, Block -> ()
(Block -> ()) -> NFData Block
forall a. (a -> ()) -> NFData a
$crnf :: Block -> ()
rnf :: Block -> ()
NFData)

newtype BlockPoint = BlockPoint Any
  deriving (BlockPoint -> BlockPoint -> Bool
(BlockPoint -> BlockPoint -> Bool)
-> (BlockPoint -> BlockPoint -> Bool) -> Eq BlockPoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlockPoint -> BlockPoint -> Bool
== :: BlockPoint -> BlockPoint -> Bool
$c/= :: BlockPoint -> BlockPoint -> Bool
/= :: BlockPoint -> BlockPoint -> Bool
Eq, Int -> BlockPoint -> ShowS
[BlockPoint] -> ShowS
BlockPoint -> String
(Int -> BlockPoint -> ShowS)
-> (BlockPoint -> String)
-> ([BlockPoint] -> ShowS)
-> Show BlockPoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BlockPoint -> ShowS
showsPrec :: Int -> BlockPoint -> ShowS
$cshow :: BlockPoint -> String
show :: BlockPoint -> String
$cshowList :: [BlockPoint] -> ShowS
showList :: [BlockPoint] -> ShowS
Show, Gen BlockPoint
Gen BlockPoint
-> (BlockPoint -> [BlockPoint]) -> Arbitrary BlockPoint
BlockPoint -> [BlockPoint]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen BlockPoint
arbitrary :: Gen BlockPoint
$cshrink :: BlockPoint -> [BlockPoint]
shrink :: BlockPoint -> [BlockPoint]
Arbitrary, [BlockPoint] -> Encoding
BlockPoint -> Encoding
(BlockPoint -> Encoding)
-> (forall s. Decoder s BlockPoint)
-> ([BlockPoint] -> Encoding)
-> (forall s. Decoder s [BlockPoint])
-> Serialise BlockPoint
forall s. Decoder s [BlockPoint]
forall s. Decoder s BlockPoint
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
$cencode :: BlockPoint -> Encoding
encode :: BlockPoint -> Encoding
$cdecode :: forall s. Decoder s BlockPoint
decode :: forall s. Decoder s BlockPoint
$cencodeList :: [BlockPoint] -> Encoding
encodeList :: [BlockPoint] -> Encoding
$cdecodeList :: forall s. Decoder s [BlockPoint]
decodeList :: forall s. Decoder s [BlockPoint]
Serialise, (forall x. BlockPoint -> Rep BlockPoint x)
-> (forall x. Rep BlockPoint x -> BlockPoint) -> Generic BlockPoint
forall x. Rep BlockPoint x -> BlockPoint
forall x. BlockPoint -> Rep BlockPoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BlockPoint -> Rep BlockPoint x
from :: forall x. BlockPoint -> Rep BlockPoint x
$cto :: forall x. Rep BlockPoint x -> BlockPoint
to :: forall x. Rep BlockPoint x -> BlockPoint
Generic, BlockPoint -> ()
(BlockPoint -> ()) -> NFData BlockPoint
forall a. (a -> ()) -> NFData a
$crnf :: BlockPoint -> ()
rnf :: BlockPoint -> ()
NFData)

blockFetchCodec :: Codec (BlockFetch Block BlockPoint)
                         CBOR.DeserialiseFailure IO BL.ByteString
blockFetchCodec :: Codec
  (BlockFetch Block BlockPoint) DeserialiseFailure IO ByteString
blockFetchCodec =
    (Block -> Encoding)
-> (forall s. Decoder s Block)
-> (BlockPoint -> Encoding)
-> (forall s. Decoder s BlockPoint)
-> Codec
     (BlockFetch Block BlockPoint) DeserialiseFailure IO ByteString
forall block point (m :: * -> *).
MonadST m =>
(block -> Encoding)
-> (forall s. Decoder s block)
-> (point -> Encoding)
-> (forall s. Decoder s point)
-> Codec (BlockFetch block point) DeserialiseFailure m ByteString
codecBlockFetch
      Block -> Encoding
forall a. Serialise a => a -> Encoding
Serialise.encode
      Decoder s Block
forall s. Decoder s Block
forall a s. Serialise a => Decoder s a
Serialise.decode
      BlockPoint -> Encoding
forall a. Serialise a => a -> Encoding
Serialise.encode
      Decoder s BlockPoint
forall s. Decoder s BlockPoint
forall a s. Serialise a => Decoder s a
Serialise.decode