{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Flat.Repr where
import qualified Data.ByteString as B
import Flat.Class (Flat (..))
import Flat.Decoder.Types (Get)
import Flat.Run (flat, unflat)
newtype Repr a = Repr {forall a. Repr a -> ByteString
repr :: B.ByteString} deriving Int -> Repr a -> ShowS
forall a. Int -> Repr a -> ShowS
forall a. [Repr a] -> ShowS
forall a. Repr a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Repr a] -> ShowS
$cshowList :: forall a. [Repr a] -> ShowS
show :: Repr a -> String
$cshow :: forall a. Repr a -> String
showsPrec :: Int -> Repr a -> ShowS
$cshowsPrec :: forall a. Int -> Repr a -> ShowS
Show
unrepr :: Flat a => Repr a -> a
unrepr :: forall a. Flat a => Repr a -> a
unrepr (Repr ByteString
bs)=
case forall a b. (Flat a, AsByteString b) => b -> Decoded a
unflat ByteString
bs of
Right a
a -> a
a
Left DecodeException
_ -> forall a. HasCallStack => String -> a
error String
"impossible"
instance Flat a => Flat (Repr a) where
size :: Repr a -> Int -> Int
size = forall a. HasCallStack => String -> a
error String
"unused"
encode :: Repr a -> Encoding
encode = forall a. HasCallStack => String -> a
error String
"unused"
decode :: Get (Repr a)
decode = forall a. ByteString -> Repr a
Repr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Flat a => a -> ByteString
flat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. Flat a => Get a
decode :: Get a)