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

import Codec.CBOR.Read qualified as CBOR
import Data.ByteString.Lazy qualified as BL
import Network.Socket (SockAddr (..))
import Network.TypedProtocol.Codec
import Ouroboros.Network.NodeToNode.Version
import Ouroboros.Network.PeerSelection.PeerSharing.Codec (decodeRemoteAddress,
           encodeRemoteAddress)
import Ouroboros.Network.Protocol.PeerSharing.Codec (codecPeerSharing)
import Ouroboros.Network.Protocol.PeerSharing.Type

peerSharingCodec :: NodeToNodeVersion
                 -> Codec (PeerSharing SockAddr)
                         CBOR.DeserialiseFailure IO BL.ByteString
peerSharingCodec :: NodeToNodeVersion
-> Codec (PeerSharing SockAddr) DeserialiseFailure IO ByteString
peerSharingCodec NodeToNodeVersion
ntnVersion =
  (SockAddr -> Encoding)
-> (forall s. Decoder s SockAddr)
-> Codec (PeerSharing SockAddr) DeserialiseFailure IO ByteString
forall (m :: * -> *) peerAddress.
MonadST m =>
(peerAddress -> Encoding)
-> (forall s. Decoder s peerAddress)
-> Codec (PeerSharing peerAddress) DeserialiseFailure m ByteString
codecPeerSharing (NodeToNodeVersion -> SockAddr -> Encoding
encodeRemoteAddress NodeToNodeVersion
ntnVersion)
                   (NodeToNodeVersion -> Decoder s SockAddr
forall s. NodeToNodeVersion -> Decoder s SockAddr
decodeRemoteAddress NodeToNodeVersion
ntnVersion)