flat-0.6: Principled and efficient bit-oriented binary serialization.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Flat.AsSize

Description

Wrapper type to decode a value to its size in bits.

See also Flat.AsBin.

In 0.5.X this type was called SizeOf.

Since: 0.6

Synopsis

Documentation

newtype AsSize a Source #

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)

Constructors

AsSize NumBits 

Instances

Instances details
Show (AsSize a) Source # 
Instance details

Defined in Flat.AsSize

Methods

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

show :: AsSize a -> String #

showList :: [AsSize a] -> ShowS #

Flat a => Flat (AsSize a) Source # 
Instance details

Defined in Flat.AsSize

Eq (AsSize a) Source # 
Instance details

Defined in Flat.AsSize

Methods

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

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

Ord (AsSize a) Source # 
Instance details

Defined in Flat.AsSize

Methods

compare :: AsSize a -> AsSize a -> Ordering #

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

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

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

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

max :: AsSize a -> AsSize a -> AsSize a #

min :: AsSize a -> AsSize a -> AsSize a #