Cabal-1.24.0.0: A framework for packaging Haskell software

Safe HaskellSafe-Inferred

Distribution.Compat.Binary

Synopsis

Documentation

decodeOrFailIO :: Binary a => ByteString -> IO (Either String a)

class Binary t where

The Binary class provides put and get, methods to encode and decode a Haskell value to a lazy ByteString. It mirrors the Read and Show classes for textual representation of Haskell types, and is suitable for serialising Haskell values to disk, over the network.

For decoding and generating simple external binary formats (e.g. C structures), Binary may be used, but in general is not suitable for complex protocols. Instead use the Put and Get primitives directly.

Instances of Binary should satisfy the following property:

 decode . encode == id

That is, the get and put methods should be the inverse of each other. A range of instances are provided for basic Haskell types.

Methods

put :: t -> Put

Encode a value in the Put monad.

get :: Get t

Decode a value in the Get monad

Instances

Binary Bool 
Binary Char 
Binary Double 
Binary Float 
Binary Int 
Binary Int8 
Binary Int16 
Binary Int32 
Binary Int64 
Binary Integer 
Binary Ordering 
Binary Word 
Binary Word8 
Binary Word16 
Binary Word32 
Binary Word64 
Binary () 
Binary ByteString 
Binary ByteString 
Binary IntSet 
Binary Version 
Binary KnownExtension 
Binary Extension 
Binary Language 
Binary VersionRange 
Binary AbiTag 
Binary CompilerInfo 
Binary CompilerId 
Binary CompilerFlavor 
Binary License 
Binary AbiHash 
Binary Dependency 
Binary UnitId 
Binary ComponentId 
Binary PackageIdentifier 
Binary PackageName 
Binary ModuleName 
Binary Platform 
Binary Arch 
Binary OS 
Binary ConfVar 
Binary FlagName 
Binary Flag 
Binary GenericPackageDescription 
Binary RepoType 
Binary RepoKind 
Binary SourceRepo 
Binary BuildInfo 
Binary BenchmarkType 
Binary BenchmarkInterface 
Binary Benchmark 
Binary TestType 
Binary TestSuiteInterface 
Binary TestSuite 
Binary Executable 
Binary ModuleReexport 
Binary Library 
Binary ModuleRenaming 
Binary SetupBuildInfo 
Binary BuildType 
Binary PackageDescription 
Binary PathTemplateVariable 
Binary PathTemplate 
Binary Verbosity 
Binary ExposedModule 
Binary OriginalModule 
Binary InstalledPackageInfo 
Binary ProfDetailLevel 
Binary DebugInfoLevel 
Binary OptimisationLevel 
Binary PackageDB 
Binary Compiler 
Binary ProgramSearchPathEntry 
Binary ProgramLocation 
Binary ConfiguredProgram 
Binary ProgramDb

Note that this instance does not preserve the known Programs. See restoreProgramDb for details.

Binary ConfigFlags 
Binary AllowNewerDep 
Binary AllowNewer 
Binary ComponentLocalBuildInfo 
Binary ComponentName 
Binary LocalBuildInfo 
Binary BuildTarget 
Binary a => Binary [a] 
(Binary a, Integral a) => Binary (Ratio a) 
Binary a => Binary (Maybe a) 
Binary a => Binary (Set a) 
Binary e => Binary (IntMap e) 
Binary e => Binary (Seq e) 
Binary e => Binary (Tree e) 
Binary a => Binary (Last' a) 
Binary c => Binary (Condition c) 
Binary dir => Binary (InstallDirs dir) 
(Ord a, Binary a) => Binary (NubList a)

Binary instance for 'NubList a' is the same as for '[a]'. For put, we just pull off constructor and put the list. For get, we get the list and make a NubList out of it using toNubList.

Binary a => Binary (PackageIndex a) 
Binary a => Binary (Flag a) 
(Binary a, Binary b) => Binary (Either a b) 
(Binary a, Binary b) => Binary (a, b) 
(Binary k, Binary e) => Binary (Map k e) 
(Binary i, Ix i, Binary e) => Binary (Array i e) 
(Binary i, Ix i, Binary e, IArray UArray e) => Binary (UArray i e) 
(Binary a, Binary b, Binary c) => Binary (a, b, c) 
(Binary v, Binary c, Binary a) => Binary (CondTree v c a) 
(Binary a, Binary b, Binary c, Binary d) => Binary (a, b, c, d) 
(Binary a, Binary b, Binary c, Binary d, Binary e) => Binary (a, b, c, d, e) 
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f) => Binary (a, b, c, d, e, f) 
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g) => Binary (a, b, c, d, e, f, g) 
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g, Binary h) => Binary (a, b, c, d, e, f, g, h) 
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g, Binary h, Binary i) => Binary (a, b, c, d, e, f, g, h, i) 
(Binary a, Binary b, Binary c, Binary d, Binary e, Binary f, Binary g, Binary h, Binary i, Binary j) => Binary (a, b, c, d, e, f, g, h, i, j) 

decode :: Binary a => ByteString -> a

Decode a value from a lazy ByteString, reconstructing the original structure.

encode :: Binary a => a -> ByteString

Encode a value using binary serialisation to a lazy ByteString.