mqtt-hs-1.0.1: A MQTT client library.

Maintainerkoomi+mqtt@hackerspace-bamberg.de
Safe HaskellNone

Network.MQTT.Types

Contents

Description

Types representing MQTT messages.

Synopsis

Messages

data Message t Source

A MQTT message, indexed by the type of the message (MsgType).

Constructors

Message 

data SomeMessage whereSource

Any message, hiding the index.

Constructors

SomeMessage :: SingI t => Message t -> SomeMessage 

data MqttHeader Source

Fixed header required in every message.

Constructors

Header 

Fields

dup :: Bool

Has this message been sent before?

qos :: QoS

Quality of Service-level

retain :: Bool

Should the broker retain the message for future subscribers?

setDup :: Message t -> Message tSource

Set the dup flag to True.

Message body

data MessageBody t whereSource

The body of a MQTT message, indexed by the type of the message (MsgType).

Constructors

Connect :: Bool -> Maybe Will -> MqttText -> Maybe MqttText -> Maybe MqttText -> Word16 -> MessageBody CONNECT 

Fields

cleanSession :: Bool

Should the server forget subscriptions and other state on disconnects?

will :: Maybe Will

Optional Will message.

clientID :: MqttText

Client ID used by the server to identify clients.

username :: Maybe MqttText

Optional username used for authentication.

password :: Maybe MqttText

Optional password used for authentication.

keepAlive :: Word16

Time (in seconds) after which a PingReq is sent to the broker if no regular message was sent. 0 means no limit.

ConnAck :: Word8 -> MessageBody CONNACK 

Fields

returnCode :: Word8
 
Publish :: Topic -> Maybe MsgID -> ByteString -> MessageBody PUBLISH 

Fields

topic :: Topic

The Topic to which the message should be published.

pubMsgID :: Maybe MsgID

MsgID of the message if QoS > NoConfirm.

payload :: ByteString

The content that will be published.

PubAck :: MsgID -> MessageBody PUBACK 

Fields

pubAckMsgID :: MsgID
 
PubRec :: MsgID -> MessageBody PUBREC 

Fields

pubRecMsgID :: MsgID
 
PubRel :: MsgID -> MessageBody PUBREL 

Fields

pubRelMsgID :: MsgID
 
PubComp :: MsgID -> MessageBody PUBCOMP 

Fields

pubCompMsgID :: MsgID
 
Subscribe :: MsgID -> [(Topic, QoS)] -> MessageBody SUBSCRIBE 

Fields

subscribeMsgID :: MsgID
 
subTopics :: [(Topic, QoS)]

The Topics and corresponding requested QoS.

SubAck :: MsgID -> [QoS] -> MessageBody SUBACK 

Fields

subAckMsgID :: MsgID
 
granted :: [QoS]

The QoS granted for each Topic in the order they were sent in the SUBSCRIBE.

Unsubscribe :: MsgID -> [Topic] -> MessageBody UNSUBSCRIBE 

Fields

unsubMsgID :: MsgID
 
unsubTopics :: [Topic]

The Topics from which the client should be unsubscribed.

UnsubAck :: MsgID -> MessageBody UNSUBACK 

Fields

unsubAckMsgID :: MsgID
 
PingReq :: MessageBody PINGREQ 
PingResp :: MessageBody PINGRESP 
Disconnect :: MessageBody DISCONNECT 

Miscellaneous

data Will Source

A Will message is published by the broker if a client disconnects without sending a DISCONNECT.

Constructors

Will 

Fields

wRetain :: Bool
 
wQoS :: QoS
 
wTopic :: Topic
 
wMsg :: MqttText
 

Instances

data QoS Source

The different levels of QoS

Constructors

NoConfirm

Fire and forget, message will be published at most once.

Confirm

Acknowledged delivery, message will be published at least once.

Handshake

Assured delivery, message will be published exactly once.

Instances

getMsgID :: MessageBody t -> Maybe MsgIDSource

Get the message ID of any message, if it exists.

data Topic Source

A topic is a "hierarchical name space that defines a taxonomy of information sources for which subscribers can register an interest." See the specification for more details.

A topic can be inspected by using the matches function or after using getLevels, e.g.:

 f1 topic
   | topic `matches` "mqtt/hs/example" = putStrLn "example"
   | topic `matches` "mqtt/hs/#" = putStrLn "wildcard"

 f2 topic = case getLevels topic of
              ["mqtt", "hs", "example"] -> putStrLn "example"
              "mqtt" : "hs" : _ -> putStrLn "wildcard"

matches :: Topic -> Topic -> BoolSource

Check if one of the Topics matches the other, taking wildcards into consideration.

getLevels :: Topic -> [Text]Source

Split a topic into its individual levels.

fromLevels :: [Text] -> TopicSource

Create a Topic from its individual levels.

newtype MqttText Source

MQTT uses length-prefixed UTF-8 as text encoding.

Constructors

MqttText 

Fields

text :: Text
 

toConnectError :: Word8 -> ConnectErrorSource

Convert a return code to a ConnectError.

Message types

data MsgType Source

The various types of messages.

Instances

toMsgType :: SingI t => Message t -> MsgTypeSource

Determine the MsgType of a Message.

Singletons

Singletons are used to build a bridge between the type and value level. See the singletons package for more information.

You do not have to use or understand these in order to use this library, they are mostly used internally to get better guarantees about the flow of Messages.

toSMsgType :: SingI t => Message t -> SMsgType tSource

Determine the singleton SMsgType of a Message.

type SMsgType z = Sing zSource

withSomeSingI :: MsgType -> (forall t. SingI t => SMsgType t -> r) -> rSource

Helper to generate both an implicit and explicit singleton.

data family Sing a