{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE CPP #-}
module Flat.Run (
flat,
flatRaw,
unflat,
unflatWith,
unflatRaw,
unflatRawWith,
) where
import qualified Data.ByteString as B
import Data.ByteString.Convert
import Flat.Class
import Flat.Decoder
import qualified Flat.Encoder as E
import Flat.Filler
flat :: Flat a => a -> B.ByteString
flat = flatRaw . postAligned
unflat :: (Flat a,AsByteString b) => b -> Decoded a
unflat = unflatWith decode
unflatWith :: AsByteString b => Get a -> b -> Decoded a
unflatWith dec = unflatRawWith (postAlignedDecoder dec)
unflatRaw :: (Flat a,AsByteString b) => b -> Decoded a
unflatRaw = unflatRawWith decode
unflatRawWith :: AsByteString b => Get a -> b -> Decoded a
unflatRawWith dec = strictDecoder dec . toByteString
flatRaw :: (Flat a, AsByteString b) => a -> b
flatRaw a = fromByteString $
E.strictEncoder
(getSize a)
#ifdef ETA_VERSION
(E.trampolineEncoding (encode a))
#else
(encode a)
#endif