time-warp-1.1.1.2: Distributed systems execution emulation

Copyright(c) Serokell 2016
LicenseGPL-3 (see the file LICENSE)
MaintainerSerokell <hi@serokell.io>
Stabilityexperimental
PortabilityPOSIX, GHC
Safe HaskellNone
LanguageHaskell2010

Control.TimeWarp.Rpc.Message

Contents

Description

This module defines typeclasses which allow to abstragate from concrete serialization strategy, and also Message type, which binds a name to request.

UPGRADE-NOTE: currently only Binary serialization is supported, need to add support for MessagePack, aeson, cereal e.t.c.

Synopsis

Message

type MessageName = Text Source #

Message name, which is expected to uniquely define type of message.

class Typeable m => Message m where Source #

Defines type with it's own MessageName.

Methods

messageName :: Proxy m -> MessageName Source #

Uniquely identifies this type

messageName :: Data m => Proxy m -> MessageName Source #

Uniquely identifies this type

formatMessage :: m -> Text Source #

Description of message, for debug purposes

formatMessage :: Buildable m => m -> Text Source #

Description of message, for debug purposes

Serialization and deserialization

class PackingType p where Source #

Defines a serialization / deserialization strategy. Deserealization is assumed to be performed in two phases:

  • byte stream -> intermediate form
  • intermediate form -> any part of message (or their combination)

Minimal complete definition

unpackMsg

Associated Types

type IntermediateForm p :: * Source #

Defines intermediate form

Methods

unpackMsg :: MonadThrow m => p -> Conduit ByteString m (IntermediateForm p) Source #

Way of unpacking raw bytes to intermediate form.

Instances

class PackingType p => Packable p r where Source #

Defines a way to serialize object r with given packing type p.

Minimal complete definition

packMsg

Methods

packMsg :: MonadThrow m => p -> Conduit r m ByteString Source #

Way of packing data to raw bytes.

class PackingType p => Unpackable p r where Source #

Defines a way to deserealize data with given packing type p and extract object r.

Minimal complete definition

extractMsgPart

Methods

extractMsgPart :: MonadThrow m => p -> IntermediateForm p -> m r Source #

Way to extract message part from intermediate form.

Basic packing types

data BinaryP header Source #

Defines way to encode Binary instances into message of format (header, [[name], content]), where [x] = (length of x, x). P here denotes to "packing".

Constructors

BinaryP 

Parts of message

This part describes different parts of message. which are enought for serializing message / could be extracted on deserializing.

| Message's content.

data NameData Source #

Message's name.

Constructors

NameData MessageName 

data RawData Source #

Designates data given from incoming message, but not deserialized to any specified object.

Constructors

RawData ByteString 

Util

messageName' :: Message m => m -> MessageName Source #

As messageName, but accepts message itself, may be more convinient is most cases.

runGetOrThrow :: MonadThrow m => Get a -> ByteString -> m a Source #

Parses given bytestring, throwing ParseError on fail.