flat-0.4.4: Principled and efficient bit-oriented binary serialization.

Safe HaskellNone
LanguageHaskell2010

Flat.Instances.Containers

Contents

Description

Instances for the containers library

Synopsis

Documentation

encodeMap :: (Flat (ContainerKey map), Flat (MapValue map), IsMap map) => map -> Encoding Source #

Encode an instance of IsMap, as a list of (Key,Value) tuples

decodeMap :: (Flat (ContainerKey map), Flat (MapValue map), IsMap map) => Get map Source #

Decode an instance of IsMap, as a list of (Key,Value) tuples

Orphan instances

Flat a => Flat (IntMap a) Source #

Maps are defined as a list of (Key,Value) tuples:

Map = List (Key,Value)

List a = Nil | Cons a (List a)
>>> tst (Data.IntMap.empty :: IntMap ())
(True,1,[0])
>>> asList Data.IntMap.fromList [(1,"a"),(2,"b")]
True
Instance details

Flat a => Flat (Tree a) Source #
>>> tst (Node (1::Word8) [Node 2 [Node 3 []], Node 4 []])
(True,39,[1,129,64,200,32])
Instance details

Flat a => Flat (Seq a) Source #

Data.Sequence.Seq is encoded as a list.

>>> asList Data.Sequence.fromList [3::Word8,4,7]
True

In flat <0.4, it was encoded as an Array.

If you want to restore the previous behaviour, use AsArray:

>>> tst $ AsArray (Data.Sequence.fromList [11::Word8,22,33])
(True,40,[3,11,22,33,0])
>>> tst $ Data.Sequence.fromList [11::Word8,22,33]
(True,28,[133,197,164,32])
Instance details

(Flat a, Ord a) => Flat (Set a) Source #

Data.Set is encoded as a list

>>> asList Data.Set.fromList [3::Word8,4,7]
True
Instance details

(Flat a, Flat b, Ord a) => Flat (Map a b) Source #

Maps are encoded as lists:

>>> tst (Data.Map.empty :: Map () ())
(True,1,[0])
>>> asList Data.Map.fromList [("a","aa"),("b","bb")]
True

Key/Values are encoded in order:

>>> let l = [("a","aa"),("b","bb")] in tst (Data.Map.fromList l) == tst (Data.Map.fromList $ Prelude.reverse l)
True

IntMap and Map are encoded in the same way:

>>> let l = [(2::Int,"b"),(1,"a")] in tst (Data.IntMap.fromList l) == tst (Data.Map.fromList l)
True
Instance details

Methods

encode :: Map a b -> Encoding Source #

decode :: Get (Map a b) Source #

size :: Map a b -> NumBits -> NumBits Source #