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

Safe HaskellNone
LanguageHaskell2010

Flat.Instances.Mono

Synopsis

Documentation

sizeSequence :: (IsSequence mono, Flat (Element mono)) => mono -> NumBits -> NumBits Source #

Calculate size of an instance of IsSequence as the sum: * of the size of all the elements * plus the size of the array constructors (1 byte every 255 elements plus one final byte)

encodeSequence :: (Flat (Element mono), MonoFoldable mono) => mono -> Encoding Source #

Encode an instance of IsSequence, as an array

decodeSequence :: (Flat (Element b), IsSequence b) => Get b Source #

Decode an instance of IsSequence, as an array

sizeList :: (MonoFoldable mono, Flat (Element mono)) => mono -> NumBits -> NumBits Source #

encodeList :: (Flat (Element mono), MonoFoldable mono) => mono -> Encoding Source #

sizeSet :: (IsSet set, Flat (Element set)) => Size set Source #

encodeSet :: (IsSet set, Flat (Element set)) => set -> Encoding Source #

decodeSet :: (IsSet set, Flat (Element set)) => Get set Source #

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

newtype AsArray a Source #

Sequences are defined as Arrays:

Array v = A0 | A1 v (Array v) | A2 v v (Array v) ... | A255 ... (Array v)

In practice, this means that the sequence is encoded as a sequence of blocks of up to 255 elements, with every block preceded by the count of the elements in the block and a final 0-length block.

Lists are defined as:

List a ≡ Nil | Cons a (List a)

The AsList/AsArray wrappers can be used to serialise sequences as Lists or Arrays

>>> tst $ AsArray ([]::[()])
(True,8,[0])
>>> tst $ AsArray [11::Word8,22,33]
(True,40,[3,11,22,33,0])
>>> tst $ AsList ([]::[()])
(True,1,[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])

Constructors

AsArray 

Fields

Instances
Eq a => Eq (AsArray a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

(==) :: AsArray a -> AsArray a -> Bool #

(/=) :: AsArray a -> AsArray a -> Bool #

Ord a => Ord (AsArray a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

compare :: AsArray a -> AsArray a -> Ordering #

(<) :: AsArray a -> AsArray a -> Bool #

(<=) :: AsArray a -> AsArray a -> Bool #

(>) :: AsArray a -> AsArray a -> Bool #

(>=) :: AsArray a -> AsArray a -> Bool #

max :: AsArray a -> AsArray a -> AsArray a #

min :: AsArray a -> AsArray a -> AsArray a #

Show a => Show (AsArray a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

showsPrec :: Int -> AsArray a -> ShowS #

show :: AsArray a -> String #

showList :: [AsArray a] -> ShowS #

(IsSequence r, Flat (Element r)) => Flat (AsArray r) Source # 
Instance details

Defined in Flat.Instances.Mono

newtype AsList a Source #

Constructors

AsList 

Fields

Instances
Eq a => Eq (AsList a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

(==) :: AsList a -> AsList a -> Bool #

(/=) :: AsList a -> AsList a -> Bool #

Ord a => Ord (AsList a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

compare :: AsList a -> AsList a -> Ordering #

(<) :: AsList a -> AsList a -> Bool #

(<=) :: AsList a -> AsList a -> Bool #

(>) :: AsList a -> AsList a -> Bool #

(>=) :: AsList a -> AsList a -> Bool #

max :: AsList a -> AsList a -> AsList a #

min :: AsList a -> AsList a -> AsList a #

Show a => Show (AsList a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

showsPrec :: Int -> AsList a -> ShowS #

show :: AsList a -> String #

showList :: [AsList a] -> ShowS #

(IsSequence l, Flat (Element l)) => Flat (AsList l) Source # 
Instance details

Defined in Flat.Instances.Mono

newtype AsSet a Source #

Constructors

AsSet 

Fields

Instances
Eq a => Eq (AsSet a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

(==) :: AsSet a -> AsSet a -> Bool #

(/=) :: AsSet a -> AsSet a -> Bool #

Ord a => Ord (AsSet a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

compare :: AsSet a -> AsSet a -> Ordering #

(<) :: AsSet a -> AsSet a -> Bool #

(<=) :: AsSet a -> AsSet a -> Bool #

(>) :: AsSet a -> AsSet a -> Bool #

(>=) :: AsSet a -> AsSet a -> Bool #

max :: AsSet a -> AsSet a -> AsSet a #

min :: AsSet a -> AsSet a -> AsSet a #

Show a => Show (AsSet a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

showsPrec :: Int -> AsSet a -> ShowS #

show :: AsSet a -> String #

showList :: [AsSet a] -> ShowS #

(IsSet set, Flat (Element set)) => Flat (AsSet set) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

encode :: AsSet set -> Encoding Source #

decode :: Get (AsSet set) Source #

size :: AsSet set -> NumBits -> NumBits Source #

newtype AsMap a Source #

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])

Constructors

AsMap 

Fields

Instances
Eq a => Eq (AsMap a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

(==) :: AsMap a -> AsMap a -> Bool #

(/=) :: AsMap a -> AsMap a -> Bool #

Ord a => Ord (AsMap a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

compare :: AsMap a -> AsMap a -> Ordering #

(<) :: AsMap a -> AsMap a -> Bool #

(<=) :: AsMap a -> AsMap a -> Bool #

(>) :: AsMap a -> AsMap a -> Bool #

(>=) :: AsMap a -> AsMap a -> Bool #

max :: AsMap a -> AsMap a -> AsMap a #

min :: AsMap a -> AsMap a -> AsMap a #

Show a => Show (AsMap a) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

showsPrec :: Int -> AsMap a -> ShowS #

show :: AsMap a -> String #

showList :: [AsMap a] -> ShowS #

(IsMap map, Flat (ContainerKey map), Flat (MapValue map)) => Flat (AsMap map) Source # 
Instance details

Defined in Flat.Instances.Mono

Methods

encode :: AsMap map -> Encoding Source #

decode :: Get (AsMap map) Source #

size :: AsMap map -> NumBits -> NumBits Source #