This module provides the Serializable
type class and
functions to convert to and from Payload
s. It's implemented
in terms of Haskell's Data.Binary. The message sending
and receiving functionality in Remote.Process depends on this.
- class (Binary a, Typeable a) => Serializable a
- serialEncode :: Serializable a => a -> IO Payload
- serialEncodePure :: Serializable a => a -> Payload
- serialDecode :: Serializable a => Payload -> IO (Maybe a)
- serialDecodePure :: Serializable a => Payload -> Maybe a
- dynamicDecodePure :: Serializable a => DynamicPayload -> Maybe a
- dynamicEncodePure :: Serializable a => a -> DynamicPayload
- data Payload
- data DynamicPayload
- type PayloadLength = Int64
- hPutPayload :: Handle -> Payload -> IO ()
- hGetPayload :: Handle -> IO Payload
- payloadLength :: Payload -> PayloadLength
- getPayloadType :: Payload -> String
- getDynamicPayloadType :: DynamicPayload -> String
- getPayloadContent :: Payload -> ByteString
- genericPut :: Data a => a -> Put
- genericGet :: Data a => Get a
Documentation
class (Binary a, Typeable a) => Serializable a Source
Data that can be sent as a message must implement
this class. The class has no functions of its own,
but instead simply requires that the type implement
both Typeable
and Binary
. Typeable can usually
be derived automatically. Binary requires the put and get
functions, which can be easily implemented by hand,
or you can use the genericGet
and genericPut
flavors,
which will work automatically for types implementing
Data
.
(Binary a, Typeable a) => Serializable a |
serialEncode :: Serializable a => a -> IO PayloadSource
serialEncodePure :: Serializable a => a -> PayloadSource
serialDecode :: Serializable a => Payload -> IO (Maybe a)Source
serialDecodePure :: Serializable a => Payload -> Maybe aSource
dynamicDecodePure :: Serializable a => DynamicPayload -> Maybe aSource
dynamicEncodePure :: Serializable a => a -> DynamicPayloadSource
data DynamicPayload Source
type PayloadLength = Int64Source
hGetPayload :: Handle -> IO PayloadSource
genericPut :: Data a => a -> PutSource
Data types that can be used in messaging must
be serializable, which means that they must implement
the get
and put
methods from Binary
. If you
are too lazy to write these functions yourself,
you can delegate responsibility to this function.
It's usually sufficient to do something like this:
import Data.Data (Data) import Data.Typeable (Typeable) import Data.Binary (Binary, get, put) data MyType = MkMyType Foobar Int [(String, Waddle Baz)] | MkSpatula deriving (Data, Typeable) instance Binary MyType where put = genericPut get = genericGet
genericGet :: Data a => Get aSource
This is the counterpart genericPut