binary-generic-0.2.1: Generic binary serialisation using binary and syb.

Stabilityexperimental
MaintainerLars Petersen <info@lars-petersen.net>
Safe HaskellSafe-Infered

Data.Binary.Generic.Extensions

Description

You can build your own type-specific stacks. For example the default stack looks like this, whereas the ordering determines, which function matches first for a specific type. This especially allows you to override the default choices:

 getExtDefault    :: Typeable a => Get a -> Get a
 getExtDefault     = getExtInteger
                   . getExtChar
                   . getExtWord
                   . getExtInt
                   . getExtFloat
                   . getExtText
                   . getExtByteString

 putExtDefault    :: Typeable a => (a -> Put) -> a -> Put
 putExtDefault     = putExtInteger
                   . putExtChar
                   . putExtWord
                   . putExtInt
                   . putExtFloat
                   . putExtText
                   . putExtByteString

Notice that these stacks have to be grounded, ideally with something that handles algebraic types. Have a look at Data.Binary.Generic how this is done for the default stack.

IMPORTANT: You cannot simply apply an extension to getGeneric or putGeneric, since these do a recursive call at the bottom level which points to the top of the stack.

Documentation

extGet :: (Monad m, Typeable a, Typeable b) => m b -> m a -> m aSource

extPut :: (Typeable a, Typeable b) => (b -> q) -> (a -> q) -> a -> qSource

putExtDefault :: Typeable a => (a -> Put) -> a -> PutSource

putExtInteger :: Typeable a => (a -> Put) -> a -> PutSource

putExtChar :: Typeable a => (a -> Put) -> a -> PutSource

putExtWord :: Typeable a => (a -> Put) -> a -> PutSource

putExtInt :: Typeable a => (a -> Put) -> a -> PutSource

putExtFloat :: Typeable a => (a -> Put) -> a -> PutSource

putExtText :: Typeable a => (a -> Put) -> a -> PutSource

putExtByteString :: Typeable a => (a -> Put) -> a -> PutSource