-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Principled and efficient bit-oriented binary serialization. -- -- Reference implementation of flat, a principled and efficient -- binary serialization format. @package flat @version 0.6 module Data.ByteString.Convert -- | Convert to/from strict ByteStrings class AsByteString a toByteString :: AsByteString a => a -> ByteString fromByteString :: AsByteString a => ByteString -> a instance Data.ByteString.Convert.AsByteString Data.ByteString.Internal.ByteString instance Data.ByteString.Convert.AsByteString Data.ByteString.Lazy.Internal.ByteString instance Data.ByteString.Convert.AsByteString [GHC.Word.Word8] -- | Primitives to convert between Float/Double and Word32/Word64. -- -- Code copied from binary. -- -- Based on: -- http://hackage.haskell.org/package/reinterpret-cast-0.1.0/docs/src/Data-ReinterpretCast-Internal-ImplArray.html.. -- -- Implements casting via a 1-element STUArray, as described in -- http://stackoverflow.com/a/7002812/263061. module Data.FloatCast -- | Reinterpret-casts a Float to a Word32. floatToWord :: Float -> Word32 -- | Reinterpret-casts a Word32 to a Float. -- --
-- \f -> wordToFloat (floatToWord f ) == f ---- -- +++ OK, passed 100 tests. -- --
-- >>> floatToWord (-0.15625) -- 3189768192 ---- --
-- >>> wordToFloat 3189768192 -- -0.15625 ---- --
-- >>> floatToWord (-5.828125) == 0xC0BA8000 -- True --wordToFloat :: Word32 -> Float -- | Reinterpret-casts a Double to a Word64. -- --
-- \f -> wordToDouble (doubleToWord f ) == f ---- -- +++ OK, passed 100 tests. -- --
-- >>> showHex (doubleToWord 1.0000000000000004) "" -- "3ff0000000000002" ---- --
-- >>> doubleToWord 1.0000000000000004 == 0x3FF0000000000002 -- True ---- --
-- >>> showHex (doubleToWord (-0.15625)) "" -- "bfc4000000000000" ---- --
-- >>> wordToDouble 0xbfc4000000000000 -- -0.15625 --doubleToWord :: Double -> Word64 -- | Reinterpret-casts a Word64 to a Double. wordToDouble :: Word64 -> Double -- | Return the value computed by a state thread. The forall -- ensures that the internal state used by the ST computation is -- inaccessible to the rest of the program. runST :: (forall s. () => ST s a) -> a -- |
-- >>> runST (cast (0xF0F1F2F3F4F5F6F7::Word64)) == (0xF0F1F2F3F4F5F6F7::Word64) -- True --cast :: (MArray (STUArray s) a (ST s), MArray (STUArray s) b (ST s)) => a -> ST s b -- | ZigZag encoding of signed integrals. module Data.ZigZag -- | Convert between a signed integral and the corresponding ZigZag encoded -- unsigned integral (e.g. between Int8 and Word8 or Integral and -- Natural). -- -- Allow conversion only between compatible types, invalid conversions -- produce a type error: -- --
-- zigZag (-1::Int64) :: Word32 -- ... -- ... Couldn't match type ... -- ... ---- --
-- >>> zigZag (0::Int8) -- 0 ---- --
-- >>> zigZag (-1::Int16) -- 1 ---- --
-- >>> zigZag (1::Int32) -- 2 ---- --
-- >>> zigZag (-2::Int16) -- 3 ---- --
-- >>> zigZag (-50::Integer) -- 99 ---- --
-- >>> zigZag (50::Integer) -- 100 ---- --
-- >>> zigZag (64::Integer) -- 128 ---- --
-- >>> zigZag (-256::Integer) -- 511 ---- --
-- >>> zigZag (256::Integer) -- 512 ---- --
-- >>> map zigZag [-3..3::Integer] -- [5,3,1,0,2,4,6] ---- --
-- >>> map zagZig [0..6::Word8] -- [0,-1,1,-2,2,-3,3] ---- --
-- \(f::Integer) -> zagZig (zigZag f) == f ---- -- +++ OK, passed 100 tests. -- --
-- \(f::Natural) -> zigZag (zagZig f) == f ---- -- +++ OK, passed 100 tests. -- --
-- \(f::Int8) -> zagZig (zigZag f) == f ---- -- +++ OK, passed 100 tests. -- --
-- \(f::Word8) -> zigZag (zagZig f) == f ---- -- +++ OK, passed 100 tests. -- --
-- \(s::Int8) -> zigZag s == fromIntegral (zigZag (fromIntegral s :: Integer)) ---- -- +++ OK, passed 100 tests. -- --
-- \(u::Word8) -> zagZig u == fromIntegral (zagZig (fromIntegral u :: Natural)) ---- -- +++ OK, passed 100 tests. -- --
-- \(f::Int64) -> zagZig (zigZag f) == f ---- -- +++ OK, passed 100 tests. -- --
-- \(f::Word64) -> zigZag (zagZig f) == f ---- -- +++ OK, passed 100 tests. -- --
-- \(s::Int64) -> zigZag s == fromIntegral (zigZag (fromIntegral s :: Integer)) ---- -- +++ OK, passed 100 tests. -- --
-- \(u::Word64) -> zagZig u == fromIntegral (zagZig (fromIntegral u :: Natural)) ---- -- +++ OK, passed 100 tests. class (Integral signed, Integral unsigned) => ZigZag signed unsigned | unsigned -> signed, signed -> unsigned zigZag :: ZigZag signed unsigned => signed -> unsigned zigZag :: (ZigZag signed unsigned, FiniteBits signed) => signed -> unsigned zagZig :: ZigZag signed unsigned => unsigned -> signed zagZig :: (ZigZag signed unsigned, Bits unsigned) => unsigned -> signed instance Data.ZigZag.ZigZag GHC.Int.Int8 GHC.Word.Word8 instance Data.ZigZag.ZigZag GHC.Int.Int16 GHC.Word.Word16 instance Data.ZigZag.ZigZag GHC.Int.Int32 GHC.Word.Word32 instance Data.ZigZag.ZigZag GHC.Int.Int64 GHC.Word.Word64 instance Data.ZigZag.ZigZag GHC.Num.Integer.Integer GHC.Num.Natural.Natural -- | Strict Decoder Types module Flat.Decoder.Types -- | A decoder. -- -- Given: -- --
-- >>> toBE32 0xF0F1F2F3 == if isBigEndian then 0xF0F1F2F3 else 0xF3F2F1F0 -- True --toBE32 :: Word32 -> Word32 -- | Convert a 64 bit value in cpu endianess to big endian -- --
-- >>> toBE64 0xF0F1F2F3F4F5F6F7 == if isBigEndian then 0xF0F1F2F3F4F5F6F7 else 0xF7F6F5F4F3F2F1F0 -- True --toBE64 :: Word64 -> Word64 -- | Convert a 16 bit value in cpu endianess to big endian -- --
-- >>> toBE16 0xF0F1 == if isBigEndian then 0xF0F1 else 0xF1F0 -- True --toBE16 :: Word16 -> Word16 isBigEndian :: Bool -- | Memory access primitives. -- -- Includes code from the store-core package. module Flat.Memory chunksToByteString :: (Ptr Word8, [Int]) -> ByteString chunksToByteArray :: (Ptr Word8, [Int]) -> (ByteArray, Int) -- | Byte arrays. data ByteArray -- | Copy ByteArray to given pointer, returns new pointer pokeByteArray :: ByteArray# -> Int -> Int -> Ptr Word8 -> IO (Ptr Word8) -- | Copy bytestring to given pointer, returns new pointer pokeByteString :: ByteString -> Ptr Word8 -> IO (Ptr Word8) unsafeCreateUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> (ByteString, a) -- | Computes the offset required to get from the second to the first -- argument. We have -- --
-- p2 == p1 `plusPtr` (p2 `minusPtr` p1) --minusPtr :: Ptr a -> Ptr b -> Int -- | Create a new bytestring, copying sourceLen bytes from sourcePtr peekByteString :: Ptr Word8 -> Int -> ByteString -- | Strict Decoder Primitives module Flat.Decoder.Prim -- | Decode a boolean dBool :: Get Bool -- | Return the 8 most significant bits (same as dBE8) dWord8 :: Get Word8 -- | Return the 8 most significant bits dBE8 :: Get Word8 -- | Return the 16 most significant bits dBE16 :: Get Word16 -- | Return the 32 most significant bits dBE32 :: Get Word32 -- | Return the 64 most significant bits dBE64 :: Get Word64 -- | Return the n most significant bits (up to maximum of 8) -- -- The bits are returned right shifted: -- --
-- >>> unflatWith (dBEBits8 3) [0b11100001::Word8] == Right 0b00000111 -- True ---- --
-- >>> unflatWith (dBEBits8 9) [0b11100001::Word8,0b11111111] -- Left (BadOp "read8: cannot read 9 bits") --dBEBits8 :: Int -> Get Word8 -- | Return the n most significant bits (up to maximum of 16) -- -- The bits are returned right shifted: -- --
-- >>> pPrint . asBits <$> unflatWith (dBEBits16 11) [0b10110111::Word8,0b11100001] -- Right 00000101 10111111 ---- -- If more than 16 bits are requested, only the last 16 are returned: -- --
-- >>> pPrint . asBits <$> unflatWith (dBEBits16 19) [0b00000000::Word8,0b11111111,0b11100001] -- Right 00000111 11111111 --dBEBits16 :: Int -> Get Word16 -- | Return the n most significant bits (up to maximum of 32) The bits are -- returned right shifted. dBEBits32 :: Int -> Get Word32 -- | Return the n most significant bits (up to maximum of 64) The bits are -- returned right shifted. dBEBits64 :: Int -> Get Word64 -- | Drop the specified number of bits dropBits :: Int -> Get () -- | Decode a Float dFloat :: Get Float -- | Decode a Double dDouble :: Get Double -- | Decode an Array (a list of chunks up to 255 bytes long) returning the -- pointer to the first data byte and a list of chunk sizes getChunksInfo :: Get (Ptr Word8, [Int]) -- | Decode a ByteString dByteString_ :: Get ByteString -- | Decode a Lazy ByteString dLazyByteString_ :: Get ByteString -- | Decode a ByteArray and its length dByteArray_ :: Get (ByteArray, Int) -- | A special state, optimised for constructor decoding. -- -- It consists of: -- --
-- >>> unflatWith (dBEBits8 3) [0b11100001::Word8] == Right 0b00000111 -- True ---- --
-- >>> unflatWith (dBEBits8 9) [0b11100001::Word8,0b11111111] -- Left (BadOp "read8: cannot read 9 bits") --dBEBits8 :: Int -> Get Word8 -- | Return the n most significant bits (up to maximum of 16) -- -- The bits are returned right shifted: -- --
-- >>> pPrint . asBits <$> unflatWith (dBEBits16 11) [0b10110111::Word8,0b11100001] -- Right 00000101 10111111 ---- -- If more than 16 bits are requested, only the last 16 are returned: -- --
-- >>> pPrint . asBits <$> unflatWith (dBEBits16 19) [0b00000000::Word8,0b11111111,0b11100001] -- Right 00000111 11111111 --dBEBits16 :: Int -> Get Word16 -- | Return the n most significant bits (up to maximum of 32) The bits are -- returned right shifted. dBEBits32 :: Int -> Get Word32 -- | Return the n most significant bits (up to maximum of 64) The bits are -- returned right shifted. dBEBits64 :: Int -> Get Word64 -- | Drop the specified number of bits dropBits :: Int -> Get () -- | A special state, optimised for constructor decoding. -- -- It consists of: -- --
-- >>> enc $ eTrueF >=> eFillerF -- "10000001" ---- --
-- >>> enc eFillerF -- "00000001" --eFillerF :: Prim eBoolF :: Bool -> Prim -- |
-- >>> enc eTrueF -- "1" --eTrueF :: Prim -- |
-- >>> enc eFalseF -- "0" --eFalseF :: Prim varWordF :: (Bits t, Integral t) => t -> Prim -- |
-- >>> enc $ \s-> eWord8F 0 s >>= updateWord8 255 s -- "11111111" ---- --
-- >>> enc $ \s0 -> eTrueF s0 >>= \s1 -> eWord8F 255 s1 >>= eWord8F 255 >>= updateWord8 0 s1 -- "10000000 01111111 1" ---- --
-- >>> enc $ \s0 -> eFalseF s0 >>= \s1 -> eWord8F 0 s1 >>= updateWord8 255 s1 -- "01111111 1" ---- --
-- >>> enc $ \s0 -> eFalseF s0 >>= \s1 -> eWord8F 0 s1 >>= updateWord8 255 s1 >>= eFalseF -- "01111111 10" ---- --
-- >>> enc $ \s0 -> eTrueF s0 >>= \s1 -> eWord8F 255 s1 >>= eTrueF >>= updateWord8 0 s1 >>= eTrueF -- "10000000 011" --updateWord8 :: Word8 -> S -> Prim w7l :: (Bits t, Integral t) => t -> [Word8] eWord32BEF :: Word32 -> Prim eWord64BEF :: Word64 -> Prim eWord32E :: (Word32 -> Word32) -> Word32 -> Prim eWord64E :: (Word64 -> Word64) -> Word64 -> Prim -- | Primitives to calculate the maximum size in bits of the encoding of a -- value module Flat.Encoder.Size sFillerMax :: NumBits sBool :: NumBits sWord8 :: NumBits sInt8 :: NumBits sFloat :: NumBits sDouble :: NumBits sChar :: Char -> NumBits sCharMax :: NumBits sWord :: Word -> NumBits sInt :: Int -> NumBits sInt16 :: Int16 -> NumBits sInt32 :: Int32 -> NumBits sInt64 :: Int64 -> NumBits sWord16 :: Word16 -> NumBits sWord32 :: Word32 -> NumBits sWord64 :: Word64 -> NumBits sInteger :: Integer -> NumBits sNatural :: Natural -> NumBits sIntegral :: (Bits t, Integral t) => t -> Int sUTF8Max :: Text -> NumBits sUTF16Max :: Text -> NumBits sBytes :: ByteString -> NumBits sLazyBytes :: ByteString -> NumBits sShortBytes :: ShortByteString -> NumBits bitsToBytes :: Int -> Int numBlks :: Integral t => t -> t -> t arrayBits :: Int -> NumBits arrayChunks :: Int -> NumBits blobBits :: Int -> NumBits blkBitsBS :: ByteString -> NumBits blksBits :: Int -> NumBits -- | Strict encoder module Flat.Encoder.Strict -- | Strict encoder strictEncoder :: NumBits -> Encoding -> ByteString numEncodedBits :: Int -> Encoding -> NumBits strictEncoderPartial :: Int -> Encoding -> (ByteString, NumBits) newtype Encoding Encoding :: Prim -> Encoding [run] :: Encoding -> Prim encodingAppend :: Encoding -> Encoding -> Encoding encodersS :: [Encoding] -> Encoding sizeListWith :: (Foldable t1, Num t2) => (t3 -> t2 -> t2) -> t1 t3 -> t2 -> t2 -- | Encode as a List encodeListWith :: (t -> Encoding) -> [t] -> Encoding -- | Encode as Array encodeArrayWith :: (t -> Encoding) -> [t] -> Encoding eChar :: Char -> Encoding eUTF16 :: Text -> Encoding eUTF8 :: Text -> Encoding eBytes :: ByteString -> Encoding eLazyBytes :: ByteString -> Encoding eShortBytes :: ShortByteString -> Encoding eNatural :: Natural -> Encoding eFloat :: Float -> Encoding eDouble :: Double -> Encoding eInteger :: Integer -> Encoding eInt64 :: Int64 -> Encoding eInt32 :: Int32 -> Encoding eInt16 :: Int16 -> Encoding eInt8 :: Int8 -> Encoding eInt :: Int -> Encoding eWord64 :: Word64 -> Encoding eWord32 :: Word32 -> Encoding eWord16 :: Word16 -> Encoding eWord8 :: Word8 -> Encoding eWord :: Word -> Encoding eBits16 :: NumBits -> Word16 -> Encoding eBits :: NumBits -> Word8 -> Encoding eFiller :: Encoding eBool :: Bool -> Encoding eTrue :: Encoding eFalse :: Encoding vsize :: (t -> NumBits) -> t -> NumBits -> NumBits csize :: NumBits -> t -> NumBits -> NumBits sChar :: Size Char sInt64 :: Size Int64 sInt32 :: Size Int32 sInt16 :: Size Int16 sInt8 :: Size Int8 sInt :: Size Int sWord64 :: Size Word64 sWord32 :: Size Word32 sWord16 :: Size Word16 sWord8 :: Size Word8 sWord :: Size Word sFloat :: Size Float sDouble :: Size Double sBytes :: Size ByteString sLazyBytes :: Size ByteString sShortBytes :: Size ShortByteString sNatural :: Size Natural sInteger :: Size Integer sUTF8Max :: Size Text sUTF16 :: Size Text sFillerMax :: Size a sBool :: Size Bool instance GHC.Show.Show Flat.Encoder.Strict.Encoding instance GHC.Base.Semigroup Flat.Encoder.Strict.Encoding instance GHC.Base.Monoid Flat.Encoder.Strict.Encoding -- | Encoder and encoding primitives module Flat.Encoder data Encoding -- | An associative operation. -- --
-- >>> [1,2,3] <> [4,5,6] -- [1,2,3,4,5,6] --(<>) :: Semigroup a => a -> a -> a infixr 6 <> -- | Number of bits type NumBits = Int encodersS :: [Encoding] -> Encoding -- | Identity of mappend -- --
-- >>> "Hello world" <> mempty -- "Hello world" --mempty :: Monoid a => a -- | Strict encoder strictEncoder :: NumBits -> Encoding -> ByteString -- |
-- >>> enc eTrueF -- "1" --eTrueF :: Prim -- |
-- >>> enc eFalseF -- "0" --eFalseF :: Prim eFloat :: Float -> Encoding eDouble :: Double -> Encoding eInteger :: Integer -> Encoding eNatural :: Natural -> Encoding eWord16 :: Word16 -> Encoding eWord32 :: Word32 -> Encoding eWord64 :: Word64 -> Encoding eWord8 :: Word8 -> Encoding eBits :: NumBits -> Word8 -> Encoding eBits16 :: NumBits -> Word16 -> Encoding eFiller :: Encoding eBool :: Bool -> Encoding eTrue :: Encoding eFalse :: Encoding eBytes :: ByteString -> Encoding eUTF16 :: Text -> Encoding eLazyBytes :: ByteString -> Encoding eShortBytes :: ShortByteString -> Encoding eInt :: Int -> Encoding eInt8 :: Int8 -> Encoding eInt16 :: Int16 -> Encoding eInt32 :: Int32 -> Encoding eInt64 :: Int64 -> Encoding eWord :: Word -> Encoding eChar :: Char -> Encoding -- | Encode as Array encodeArrayWith :: (t -> Encoding) -> [t] -> Encoding -- | Encode as a List encodeListWith :: (t -> Encoding) -> [t] -> Encoding -- | Add the maximum size in bits of the encoding of value a to a NumBits type Size a = a -> NumBits -> NumBits arrayBits :: Int -> NumBits sWord :: Size Word sWord8 :: Size Word8 sWord16 :: Size Word16 sWord32 :: Size Word32 sWord64 :: Size Word64 sInt :: Size Int sInt8 :: Size Int8 sInt16 :: Size Int16 sInt32 :: Size Int32 sInt64 :: Size Int64 sNatural :: Size Natural sInteger :: Size Integer sFloat :: Size Float sDouble :: Size Double sChar :: Size Char sBytes :: Size ByteString sLazyBytes :: Size ByteString sShortBytes :: Size ShortByteString sUTF16 :: Size Text sFillerMax :: Size a sBool :: Size Bool sUTF8Max :: Size Text eUTF8 :: Text -> Encoding -- | Generics-based generation of Flat instances module Flat.Class -- | Class of types that can be encoded/decoded -- -- Encoding a value involves three steps: -- --
-- >>> tst (UTF8Text $ T.pack "日日日") == tst (T.pack "日日日") -- True ---- -- A wrapper to encode/decode Text as UTF8 newtype UTF8Text UTF8Text :: Text -> UTF8Text [unUTF8] :: UTF8Text -> Text -- |
-- >>> tt (UTF16Text $ T.pack "aaa") -- (True,[1,6,97,0,97,0,97,0,0]) ---- --
-- >>> tt (UTF16Text $ T.pack "𐍈𐍈𐍈") -- (True,[1,12,0,216,72,223,0,216,72,223,0,216,72,223,0]) ---- -- A wrapper to encode/decode Text as UTF16 newtype UTF16Text UTF16Text :: Text -> UTF16Text [unUTF16] :: UTF16Text -> Text instance GHC.Show.Show Flat.Instances.Text.UTF8Text instance GHC.Classes.Ord Flat.Instances.Text.UTF8Text instance GHC.Classes.Eq Flat.Instances.Text.UTF8Text instance GHC.Show.Show Flat.Instances.Text.UTF16Text instance GHC.Classes.Ord Flat.Instances.Text.UTF16Text instance GHC.Classes.Eq Flat.Instances.Text.UTF16Text instance Flat.Class.Flat Flat.Instances.Text.UTF16Text instance Flat.Class.Flat Flat.Instances.Text.UTF8Text instance Flat.Class.Flat Data.Text.Internal.Text instance Flat.Class.Flat Data.Text.Internal.Lazy.Text module Flat.Instances.Mono -- | Calculate size of an instance of IsSequence as the sum: -- --
-- >>> flatBits $ AsList [True,True,True] -- "1111110" ---- -- So we have Cons True (11) repeated three times, followed by a final -- Nil (0). -- -- The list encoding is the default one for lists so AsList is in this -- case unnecessary: -- --
-- >>> flatBits $ [True,True,True] -- "1111110" ---- -- We can force a list to be encoded as an Array with AsArray: -- --
-- >>> flatBits $ AsArray [True,True,True] -- "00000011 11100000 000" ---- -- We have the initial block with a count of 3 (3 == 00000011) followed -- by the elements True True True (111) and then the final block of 0 -- elements ("00000 000"). -- --
-- >>> flatBits $ [AsArray [True,True,True]] -- "10000001 11110000 00000" ---- --
-- >>> flatBits $ (True,True,True,AsArray $ replicate 7 True) -- "11100000 11111111 11000000 00" ---- --
-- >>> flatBits $ AsArray ([]::[()]) -- "00000000" ---- --
-- >>> flatBits $ AsList ([]::[()]) -- "0" ---- --
-- >>> tst (AsList [11::Word8,22,33]) -- (True,28,[133,197,164,32]) ---- --
-- >>> tst (AsSet (Data.Set.fromList [11::Word8,22,33])) -- (True,28,[133,197,164,32]) ---- --
-- >>> tst [AsArray [1..3], AsArray [4..8]] -- (True,99,[129,129,2,3,0,65,66,2,131,3,132,0,0]) ---- --
-- >>> tst $ [AsArray [(1::Word8)..3], AsArray [4..8]] -- (True,99,[129,128,129,1,128,65,65,1,65,129,194,0,0]) ---- --
-- >>> tst $ [AsArray [(1::Int)..3]] -- (True,42,[129,129,2,3,0,0]) --newtype AsArray a AsArray :: a -> AsArray a [unArray] :: AsArray a -> a newtype AsList a AsList :: a -> AsList a [unList] :: AsList a -> a -- | Sets are saved as lists of values. -- --
-- >>> tstBits $ AsSet (Data.Set.fromList ([False,True,False]::[Bool])) -- (True,5,"10110") --newtype AsSet a AsSet :: a -> AsSet a [unSet] :: AsSet a -> a -- | Maps are saved as lists of (key,value) tuples. -- --
-- >>> tst (AsMap (Data.Map.fromList ([]::[(Word8,())]))) -- (True,1,[0]) ---- --
-- >>> tst (AsMap (Data.Map.fromList [(3::Word,9::Word)])) -- (True,18,[129,132,128]) --newtype AsMap a AsMap :: a -> AsMap a [unMap] :: AsMap a -> a instance GHC.Classes.Ord a => GHC.Classes.Ord (Flat.Instances.Mono.AsArray a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Flat.Instances.Mono.AsArray a) instance GHC.Show.Show a => GHC.Show.Show (Flat.Instances.Mono.AsArray a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Flat.Instances.Mono.AsList a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Flat.Instances.Mono.AsList a) instance GHC.Show.Show a => GHC.Show.Show (Flat.Instances.Mono.AsList a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Flat.Instances.Mono.AsSet a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Flat.Instances.Mono.AsSet a) instance GHC.Show.Show a => GHC.Show.Show (Flat.Instances.Mono.AsSet a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Flat.Instances.Mono.AsMap a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Flat.Instances.Mono.AsMap a) instance GHC.Show.Show a => GHC.Show.Show (Flat.Instances.Mono.AsMap a) instance (Data.Containers.IsMap map, Flat.Class.Flat (Data.Containers.ContainerKey map), Flat.Class.Flat (Data.Containers.MapValue map)) => Flat.Class.Flat (Flat.Instances.Mono.AsMap map) instance (Data.Containers.IsSet set, Flat.Class.Flat (Data.MonoTraversable.Element set)) => Flat.Class.Flat (Flat.Instances.Mono.AsSet set) instance (Data.Sequences.IsSequence l, Flat.Class.Flat (Data.MonoTraversable.Element l)) => Flat.Class.Flat (Flat.Instances.Mono.AsList l) instance (Data.Sequences.IsSequence r, Flat.Class.Flat (Data.MonoTraversable.Element r)) => Flat.Class.Flat (Flat.Instances.Mono.AsArray r) -- | Flat instances for the vector package. module Flat.Instances.Vector instance Flat.Class.Flat a => Flat.Class.Flat (Data.Vector.Vector a) instance (Data.Vector.Unboxed.Base.Unbox a, Flat.Class.Flat a) => Flat.Class.Flat (Data.Vector.Unboxed.Base.Vector a) instance (Foreign.Storable.Storable a, Flat.Class.Flat a) => Flat.Class.Flat (Data.Vector.Storable.Vector a) module Flat.Instances.Unordered instance (Data.Hashable.Class.Hashable a, GHC.Classes.Eq a, Flat.Class.Flat a) => Flat.Class.Flat (Data.HashSet.Internal.HashSet a) instance (Data.Hashable.Class.Hashable k, GHC.Classes.Eq k, Flat.Class.Flat k, Flat.Class.Flat v) => Flat.Class.Flat (Data.HashMap.Internal.HashMap k v) -- | Flat instances for the base library module Flat.Instances.Base instance Flat.Class.Flat Data.Semigroup.Internal.All instance Flat.Class.Flat (f a) => Flat.Class.Flat (Data.Semigroup.Internal.Alt f a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Functor.Identity.Identity a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Semigroup.Internal.Dual a) instance Flat.Class.Flat Data.Semigroup.Internal.Any instance Flat.Class.Flat a => Flat.Class.Flat (Data.Semigroup.Internal.Sum a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Semigroup.Internal.Product a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Semigroup.Min a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Semigroup.Max a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Semigroup.First a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Semigroup.Last a) instance Flat.Class.Flat () instance Flat.Class.Flat GHC.Types.Bool instance Flat.Class.Flat GHC.Types.Char instance Flat.Class.Flat a => Flat.Class.Flat (GHC.Maybe.Maybe a) instance (Flat.Class.Flat a, Flat.Class.Flat b) => Flat.Class.Flat (Data.Either.Either a b) instance Flat.Class.Flat (Data.Fixed.Fixed a) instance Flat.Class.Flat GHC.Word.Word8 instance Flat.Class.Flat GHC.Types.Word instance Flat.Class.Flat GHC.Num.Natural.Natural instance Flat.Class.Flat GHC.Word.Word16 instance Flat.Class.Flat GHC.Word.Word32 instance Flat.Class.Flat GHC.Word.Word64 instance Flat.Class.Flat GHC.Types.Int instance Flat.Class.Flat GHC.Num.Integer.Integer instance Flat.Class.Flat GHC.Int.Int8 instance Flat.Class.Flat GHC.Int.Int16 instance Flat.Class.Flat GHC.Int.Int32 instance Flat.Class.Flat GHC.Int.Int64 instance Flat.Class.Flat GHC.Types.Float instance Flat.Class.Flat GHC.Types.Double instance Flat.Class.Flat a => Flat.Class.Flat (Data.Complex.Complex a) instance (GHC.Real.Integral a, Flat.Class.Flat a) => Flat.Class.Flat (GHC.Real.Ratio a) instance Flat.Class.Flat a => Flat.Class.Flat [a] instance Flat.Class.Flat a => Flat.Class.Flat (GHC.Base.NonEmpty a) instance (Flat.Class.Flat a, Flat.Class.Flat b) => Flat.Class.Flat (a, b) instance (Flat.Class.Flat a, Flat.Class.Flat b, Flat.Class.Flat c) => Flat.Class.Flat (a, b, c) instance (Flat.Class.Flat a, Flat.Class.Flat b, Flat.Class.Flat c, Flat.Class.Flat d) => Flat.Class.Flat (a, b, c, d) instance (Flat.Class.Flat a, Flat.Class.Flat b, Flat.Class.Flat c, Flat.Class.Flat d, Flat.Class.Flat e) => Flat.Class.Flat (a, b, c, d, e) instance (Flat.Class.Flat a, Flat.Class.Flat b, Flat.Class.Flat c, Flat.Class.Flat d, Flat.Class.Flat e, Flat.Class.Flat f) => Flat.Class.Flat (a, b, c, d, e, f) instance (Flat.Class.Flat a, Flat.Class.Flat b, Flat.Class.Flat c, Flat.Class.Flat d, Flat.Class.Flat e, Flat.Class.Flat f, Flat.Class.Flat g) => Flat.Class.Flat (a, b, c, d, e, f, g) -- | Instances for the containers library module Flat.Instances.Containers sizeMap :: (Flat (ContainerKey r), Flat (MapValue r), IsMap r) => Size r -- | Encode an instance of IsMap, as a list of (Key,Value) tuples encodeMap :: (Flat (ContainerKey map), Flat (MapValue map), IsMap map) => map -> Encoding -- | Decode an instance of IsMap, as a list of (Key,Value) tuples decodeMap :: (Flat (ContainerKey map), Flat (MapValue map), IsMap map) => Get map instance Flat.Class.Flat a => Flat.Class.Flat (Data.IntMap.Internal.IntMap a) instance (Flat.Class.Flat a, Flat.Class.Flat b, GHC.Classes.Ord a) => Flat.Class.Flat (Data.Map.Internal.Map a b) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Sequence.Internal.Seq a) instance (Flat.Class.Flat a, GHC.Classes.Ord a) => Flat.Class.Flat (Data.Set.Internal.Set a) instance Flat.Class.Flat a => Flat.Class.Flat (Data.Tree.Tree a) module Flat.Instances.Extra instance Flat.Class.Flat [GHC.Types.Char] module Flat.Instances.DList instance Flat.Class.Flat a => Flat.Class.Flat (Data.DList.Internal.DList a) -- | Flat instances for the bytestring library module Flat.Instances.ByteString instance Flat.Class.Flat Data.ByteString.Internal.ByteString instance Flat.Class.Flat Data.ByteString.Lazy.Internal.ByteString instance Flat.Class.Flat Data.ByteString.Short.Internal.ShortByteString -- | Flat instances for the array package module Flat.Instances.Array instance (Flat.Class.Flat i, Flat.Class.Flat e, GHC.Ix.Ix i) => Flat.Class.Flat (GHC.Arr.Array i e) instance (Flat.Class.Flat i, Flat.Class.Flat e, GHC.Ix.Ix i, Data.Array.Base.IArray Data.Array.Base.UArray e) => Flat.Class.Flat (Data.Array.Base.UArray i e) -- | Flat Instances for common data types from the packages on which -- flat has a dependency. module Flat.Instances -- | Pre-value and post-value byte alignments module Flat.Filler -- | A meaningless sequence of 0 bits terminated with a 1 bit (easier to -- implement than the reverse) -- -- Used to align encoded values at byte/word boundaries. data Filler FillerBit :: !Filler -> Filler FillerEnd :: Filler -- | Length of a filler in bits fillerLength :: Num a => Filler -> a -- | A Pre aligned value, a value preceded by a filler -- -- Useful to prealign ByteArrays, Texts and any structure that can be -- encoded more efficiently when byte aligned. data PreAligned a PreAligned :: Filler -> a -> PreAligned a [preFiller] :: PreAligned a -> Filler [preValue] :: PreAligned a -> a -- | Pre align a value preAligned :: a -> PreAligned a -- | A Post aligned value, a value followed by a filler -- -- Useful to complete the encoding of a top-level value data PostAligned a PostAligned :: a -> Filler -> PostAligned a [postValue] :: PostAligned a -> a [postFiller] :: PostAligned a -> Filler -- | Post align a value postAligned :: a -> PostAligned a -- | Decode a value assuming that is PreAligned preAlignedDecoder :: Get b -> Get b -- | Decode a value assuming that is PostAligned postAlignedDecoder :: Get b -> Get b instance Control.DeepSeq.NFData Flat.Filler.Filler instance GHC.Generics.Generic Flat.Filler.Filler instance GHC.Classes.Ord Flat.Filler.Filler instance GHC.Classes.Eq Flat.Filler.Filler instance GHC.Show.Show Flat.Filler.Filler instance Flat.Class.Flat a => Flat.Class.Flat (Flat.Filler.PostAligned a) instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Flat.Filler.PostAligned a) instance GHC.Generics.Generic (Flat.Filler.PostAligned a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Flat.Filler.PostAligned a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Flat.Filler.PostAligned a) instance GHC.Show.Show a => GHC.Show.Show (Flat.Filler.PostAligned a) instance Flat.Class.Flat a => Flat.Class.Flat (Flat.Filler.PreAligned a) instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Flat.Filler.PreAligned a) instance GHC.Generics.Generic (Flat.Filler.PreAligned a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Flat.Filler.PreAligned a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Flat.Filler.PreAligned a) instance GHC.Show.Show a => GHC.Show.Show (Flat.Filler.PreAligned a) instance Flat.Class.Flat Flat.Filler.Filler -- | Encoding and decoding functions module Flat.Run -- | Encode padded value. flat :: Flat a => a -> ByteString -- | Encode unpadded value flatRaw :: (Flat a, AsByteString b) => a -> b -- | Decode padded value. unflat :: (Flat a, AsByteString b) => b -> Decoded a -- | Decode padded value, using the provided unpadded decoder. unflatWith :: AsByteString b => Get a -> b -> Decoded a -- | Decode unpadded value. unflatRaw :: (Flat a, AsByteString b) => b -> Decoded a -- | Unflat unpadded value, using provided decoder unflatRawWith :: AsByteString b => Get a -> b -> Decoded a unflatRawWithOffset :: AsByteString b => Get a -> b -> NumBits -> Decoded a -- | Utilities to represent and display bit sequences module Flat.Bits -- | A sequence of bits type Bits = Vector Bool toBools :: Bits -> [Bool] fromBools :: [Bool] -> Bits -- | The sequence of bits corresponding to the serialization of the passed -- value (without any final byte padding) -- --
-- >>> bits True -- [True] --bits :: forall a. Flat a => a -> Bits -- | The sequence of bits corresponding to the byte-padded serialization of -- the passed value -- --
-- >>> paddedBits True -- [True,False,False,False,False,False,False,True] --paddedBits :: forall a. Flat a => a -> Bits -- | Convert a sequence of bits to the corresponding list of bytes -- --
-- >>> asBytes $ asBits (256+3::Word16) -- [1,3] --asBytes :: Bits -> [Word8] -- | Convert an integral value to its equivalent bit representation -- --
-- >>> asBits (5::Word8) -- [False,False,False,False,False,True,False,True] --asBits :: FiniteBits a => a -> Bits takeBits :: Int -> ByteString -> Bits takeAllBits :: ByteString -> Bits instance Text.PrettyPrint.HughesPJClass.Pretty Flat.Bits.Bits -- | doctest utilities module Flat.Instances.Test -- | Returns: result of flat/unflat test, encoding size in bits, byte -- encoding tst :: (Eq a, Flat a) => a -> (Bool, NumBits, [Word8]) -- | Returns: result of flat/unflat test, encoding size in bits, bits -- encoding tstBits :: (Eq a, Flat a) => a -> (Bool, NumBits, String) -- | Test that container is serialised as a List asList :: (Eq a1, Eq a2, Flat a1, Flat a2) => (a2 -> a1) -> a2 -> Bool flatBits :: Flat a => a -> String allBits :: Flat a => a -> String encBits :: NumBits -> Encoding -> Bits -- | Pretty print a value with the prettyNormal level. prettyShow :: Pretty a => a -> String -- | Wrapper type to decode a value to its flat serialisation. -- -- See ../test/Big.hs for an example of use. -- -- See also listTDecoder and Flat.AsSize for other ways to -- handle large decoded values. -- -- In 0.5.X this type was called Repr. module Flat.AsBin -- | When the flat serialisation of a value takes a lot less memory than -- the value itself, it can be convenient to keep the value in its -- encoded representation and decode it on demand. -- -- To do so, just decode a value a as a `AsBin a`. -- -- Examples: -- -- Encode a list of Ints and then decode it to a list of AsBin Int: -- --
-- >>> unflat (flat [1::Int .. 3]) :: Decoded ([AsBin Int])
-- Right [AsBin {repr = "\129A", offsetBits = 1},AsBin {repr = "A ", offsetBits = 2},AsBin {repr = " \193", offsetBits = 3}]
--
--
-- To decode an `AsBin a` to an a, use unbin:
--
-- -- >>> unbin <$> (unflat (flat 'a') :: Decoded (AsBin Char)) -- Right 'a' ---- -- Keep the values of a list of Ints encoded and decode just one on -- demand: -- --
-- >>> let Right l :: Decoded [AsBin Int] = unflat (flat [1..5]) in unbin (l !! 2) -- 3 ---- -- Show exactly how values are encoded: -- --
-- >>> let Right t :: Decoded (AsBin Bool,AsBin Word8,AsBin Bool) = unflat (flat (False,3:: Word64,True)) in prettyShow t -- "(0, _0000001 1, _1)" ---- -- Ten bits in total spread over two bytes: -- --
-- 0 -- _0000001 1 -- _1 -- = -- 00000001 11 ---- -- Tests: -- --
-- >>> unflat (flat ()) :: Decoded (AsBin ())
-- Right (AsBin {repr = "", offsetBits = 0})
--
--
--
-- >>> unflat (flat (False,True)) :: Decoded (Bool,AsBin Bool)
-- Right (False,AsBin {repr = "A", offsetBits = 1})
--
--
--
-- >>> unflat (flat (False,False,255 :: Word8)) :: Decoded (Bool,Bool,AsBin Word8)
-- Right (False,False,AsBin {repr = "?\193", offsetBits = 2})
--
--
-- -- >>> let Right (b0,b1,rw,b3) :: Decoded (Bool,Bool,AsBin Word8,Bool) = unflat (flat (False,False,255 :: Word8,True)) in (b0,b1,unbin rw,b3) -- (False,False,255,True) --data AsBin a -- | Decode a value unbin :: Flat a => AsBin a -> a instance GHC.Show.Show (Flat.AsBin.AsBin a) instance Flat.Class.Flat a => Text.PrettyPrint.HughesPJClass.Pretty (Flat.AsBin.AsBin a) instance Flat.Class.Flat a => Flat.Class.Flat (Flat.AsBin.AsBin a) -- | Wrapper type to decode a value to its size in bits. -- -- See also Flat.AsBin. -- -- In 0.5.X this type was called SizeOf. module Flat.AsSize -- | Useful to skip unnecessary values and to check encoding sizes. -- -- Examples: -- -- Ignore the second and fourth component of a tuple: -- --
-- >>> let v = flat ('a',"abc",'z',True) in unflat v :: Decoded (Char,AsSize String,Char,AsSize Bool)
-- Right ('a',AsSize 28,'z',AsSize 1)
--
--
-- Notice the variable size encoding of Words:
--
-- -- >>> unflat (flat (1::Word16,1::Word64)) :: Decoded (AsSize Word16,AsSize Word64) -- Right (AsSize 8,AsSize 8) ---- -- Text: -- --
-- >>> unflat (flat (T.pack "",T.pack "a",T.pack "主",UTF8Text $ T.pack "主",UTF16Text $ T.pack "主",UTF16Text $ T.pack "a")) :: Decoded (AsSize T.Text,AsSize T.Text,AsSize T.Text,AsSize UTF8Text,AsSize UTF16Text,AsSize UTF16Text) -- Right (AsSize 16,AsSize 32,AsSize 48,AsSize 48,AsSize 40,AsSize 40) ---- -- Various encodings: -- --
-- >>> unflat (flat (False,[T.pack "",T.pack "a",T.pack "主"],'a')) :: Decoded (AsSize Bool,AsSize [T.Text],AsSize Char) -- Right (AsSize 1,AsSize 96,AsSize 8) --newtype AsSize a AsSize :: NumBits -> AsSize a instance GHC.Show.Show (Flat.AsSize.AsSize a) instance GHC.Classes.Ord (Flat.AsSize.AsSize a) instance GHC.Classes.Eq (Flat.AsSize.AsSize a) instance Flat.Class.Flat a => Flat.Class.Flat (Flat.AsSize.AsSize a) -- | Haskell implementation of Flat, a principled, portable and -- efficient binary data format. module Flat -- | A decoded value type Decoded a = Either DecodeException a -- | An exception during decoding data DecodeException NotEnoughSpace :: Env -> DecodeException TooMuchSpace :: Env -> DecodeException BadEncoding :: Env -> String -> DecodeException BadOp :: String -> DecodeException