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

Description

For any algebraic datatype just make it an instance of class Data.Data.Data by simply deriving Data on definition or try stand-alone-deriving. This allows the library to enumerate the value constructors and thereby encoding their index. Notice that serialisation depends on a type's structure. Serialisations might get unreadable if the type is altered.

getGeneric and putGeneric implement a selection of type-specific defaults and are grounded by a canonical serialisation for all algebraic types that instantiate Data. Have a look at Data.Binary.Generic.Extensions for details.

If you want to ground your own type-specific stack myStack of extensions write the following for the Get-part (the Put-part follows analogously):

 getMyStack :: Data a => Get a
 getMyStack  = myStack (getGenericByCallback getMyStack)

Documentation

getGenericByCallback :: Data a => (forall d. Data d => Get d) -> Get aSource

putGenericByCallback :: Data a => (forall d. Data d => d -> Put) -> a -> PutSource