{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Data.Flat.Run (
flat,
flatRaw,
unflat,
unflatWith,
unflatRaw,
unflatRawWith,
) where
import qualified Data.ByteString as B
import Data.ByteString.Convert
import Data.Flat.Class
import Data.Flat.Decoder
import qualified Data.Flat.Encoder as E
import Data.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) (encode a)