module Blockfrost.Types.Shared.CBOR
where
import Data.ByteString.Lazy (ByteString)
import Servant.API (Accept (..), MimeRender (..), MimeUnrender (..))
import Servant.Docs (ToSample (..), singleSample)
data CBOR
newtype CBORString = CBORString ByteString
deriving stock (CBORString -> CBORString -> Bool
(CBORString -> CBORString -> Bool)
-> (CBORString -> CBORString -> Bool) -> Eq CBORString
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CBORString -> CBORString -> Bool
$c/= :: CBORString -> CBORString -> Bool
== :: CBORString -> CBORString -> Bool
$c== :: CBORString -> CBORString -> Bool
Eq, Int -> CBORString -> ShowS
[CBORString] -> ShowS
CBORString -> String
(Int -> CBORString -> ShowS)
-> (CBORString -> String)
-> ([CBORString] -> ShowS)
-> Show CBORString
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CBORString] -> ShowS
$cshowList :: [CBORString] -> ShowS
show :: CBORString -> String
$cshow :: CBORString -> String
showsPrec :: Int -> CBORString -> ShowS
$cshowsPrec :: Int -> CBORString -> ShowS
Show)
instance Accept CBOR where
contentType :: Proxy CBOR -> MediaType
contentType = MediaType -> Proxy CBOR -> MediaType
forall (f :: * -> *) a. Applicative f => a -> f a
pure MediaType
"application/cbor"
instance MimeRender CBOR CBORString where
mimeRender :: Proxy CBOR -> CBORString -> ByteString
mimeRender Proxy CBOR
_ (CBORString ByteString
cs) = ByteString
cs
instance MimeUnrender CBOR CBORString where
mimeUnrender :: Proxy CBOR -> ByteString -> Either String CBORString
mimeUnrender Proxy CBOR
_ ByteString
lbs = CBORString -> Either String CBORString
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CBORString -> Either String CBORString)
-> CBORString -> Either String CBORString
forall a b. (a -> b) -> a -> b
$ ByteString -> CBORString
CBORString ByteString
lbs
instance ToSample CBORString where
toSamples :: Proxy CBORString -> [(Text, CBORString)]
toSamples = [(Text, CBORString)] -> Proxy CBORString -> [(Text, CBORString)]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(Text, CBORString)] -> Proxy CBORString -> [(Text, CBORString)])
-> [(Text, CBORString)] -> Proxy CBORString -> [(Text, CBORString)]
forall a b. (a -> b) -> a -> b
$ CBORString -> [(Text, CBORString)]
forall a. a -> [(Text, a)]
singleSample (CBORString -> [(Text, CBORString)])
-> CBORString -> [(Text, CBORString)]
forall a b. (a -> b) -> a -> b
$ ByteString -> CBORString
CBORString ByteString
"adef"