{-# OPTIONS_GHC -Wno-orphans #-}

-- | Raw binary serialisation
--
-- The types and functions of this module now live in the cardano-keys package;
-- re-exported here for compatibility, together with the 'Error' instances and
-- the parser this API adds on top of them.
module Cardano.Api.Serialise.Raw
  ( module Cardano.Keys.Serialise.Raw
  , parseRawBytesHex
  )
where

import Cardano.Api.Error (Error (..), failEitherError)
import Cardano.Api.Parser.Text qualified as P

import Cardano.Keys.Serialise.Raw

import Data.ByteString.Char8 qualified as BSC

-- | Parse hex representation of a value
parseRawBytesHex :: SerialiseAsRawBytes a => P.Parser a
parseRawBytesHex :: forall a. SerialiseAsRawBytes a => Parser a
parseRawBytesHex = do
  input <- ParsecT Text () Identity Char -> ParsecT Text () Identity [Char]
forall a.
ParsecT Text () Identity a -> ParsecT Text () Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
P.many ParsecT Text () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
P.hexDigit
  failEitherError . deserialiseFromRawBytesHex $ BSC.pack input

instance Error RawBytesHexError where
  prettyError :: forall ann. RawBytesHexError -> Doc ann
prettyError = RawBytesHexError -> Doc ann
forall ann. RawBytesHexError -> Doc ann
renderRawBytesHexError

instance Error SerialiseAsRawBytesError where
  prettyError :: forall ann. SerialiseAsRawBytesError -> Doc ann
prettyError = SerialiseAsRawBytesError -> Doc ann
forall ann. SerialiseAsRawBytesError -> Doc ann
renderSerialiseAsRawBytesError