module Data.Flat.Run (
flat,
flatStrict,
unflat,
unflatStrict,
unflatWith,
unflatRaw,
--unflatRawWith,
) where
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import Data.Flat.Class
import Data.Flat.Decoder
import qualified Data.Flat.Encoder as E
import Data.Flat.Filler
flatStrict :: Flat a => a -> B.ByteString
flatStrict = flat
flat :: (FlatRaw (PostAligned a) c, Flat a) => a -> c
flat = flatRaw . postAligned
unflatStrict :: Flat a => B.ByteString -> Decoded a
unflatStrict = unflat
unflat :: (FlatRaw (PostAligned a) b, Flat a) => b -> Decoded a
unflat = unflatWith decode
unflatWith :: FlatRaw (PostAligned a) b => Get (PostAligned a) -> b -> Decoded a
unflatWith dec bs = postValue <$> unflatRawWith dec bs
unflatRaw :: (FlatRaw a b, Flat a) => b -> Decoded a
unflatRaw = unflatRawWith decode
class FlatRaw a b where
flatRaw :: Flat a => a -> b
unflatRawWith :: Get a -> b -> Decoded a
instance Flat a => FlatRaw a B.ByteString where
flatRaw a = E.strictEncoder (getSize a) (encode a)
unflatRawWith = strictDecoder
instance Flat a => FlatRaw a L.ByteString where
flatRaw = L.fromStrict . flatRaw
unflatRawWith dec = unflatRawWith dec . L.toStrict