Maintainer | koomi+mqtt@hackerspace-bamberg.de |
---|---|
Safe Haskell | None |
Types representing MQTT messages.
- data Message t = Message {
- header :: MqttHeader
- body :: MessageBody t
- data SomeMessage where
- SomeMessage :: SingI t => Message t -> SomeMessage
- data MqttHeader = Header {}
- setDup :: Message t -> Message t
- data MessageBody t where
- Connect :: {
- cleanSession :: Bool
- will :: Maybe Will
- clientID :: MqttText
- username :: Maybe MqttText
- password :: Maybe MqttText
- keepAlive :: Word16
- ConnAck :: {
- returnCode :: Word8
- Publish :: { } -> MessageBody PUBLISH
- PubAck :: {
- pubAckMsgID :: MsgID
- PubRec :: {
- pubRecMsgID :: MsgID
- PubRel :: {
- pubRelMsgID :: MsgID
- PubComp :: { } -> MessageBody PUBCOMP
- Subscribe :: {
- subscribeMsgID :: MsgID
- subTopics :: [(Topic, QoS)]
- SubAck :: {
- subAckMsgID :: MsgID
- granted :: [QoS]
- Unsubscribe :: {
- unsubMsgID :: MsgID
- unsubTopics :: [Topic]
- UnsubAck :: { } -> MessageBody UNSUBACK
- PingReq :: MessageBody PINGREQ
- PingResp :: MessageBody PINGRESP
- Disconnect :: MessageBody DISCONNECT
- Connect :: {
- data Will = Will {}
- data QoS
- type MsgID = Word16
- getMsgID :: MessageBody t -> Maybe MsgID
- data Topic
- matches :: Topic -> Topic -> Bool
- fromTopic :: Topic -> MqttText
- toTopic :: MqttText -> Topic
- getLevels :: Topic -> [Text]
- fromLevels :: [Text] -> Topic
- newtype MqttText = MqttText {
- text :: Text
- data ConnectError
- toConnectError :: Word8 -> ConnectError
- data MsgType
- toMsgType :: SingI t => Message t -> MsgType
- toMsgType' :: SomeMessage -> MsgType
- toSMsgType :: SingI t => Message t -> SMsgType t
- type SMsgType z = Sing z
- withSomeSingI :: MsgType -> (forall t. SingI t => SMsgType t -> r) -> r
- data family Sing a
Messages
A MQTT message, indexed by the type of the message (MsgType
).
Message | |
|
data SomeMessage whereSource
Any message, hiding the index.
SomeMessage :: SingI t => Message t -> SomeMessage |
Message body
data MessageBody t whereSource
The body of a MQTT message, indexed by the type of the message (MsgType
).
Miscellaneous
A Will message is published by the broker if a client disconnects without sending a DISCONNECT.
The different levels of QoS
getMsgID :: MessageBody t -> Maybe MsgIDSource
Get the message ID of any message, if it exists.
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"
fromLevels :: [Text] -> TopicSource
Create a Topic
from its individual levels.
MQTT uses length-prefixed UTF-8 as text encoding.
data ConnectError Source
Reasons why connecting to a broker might fail.
toConnectError :: Word8 -> ConnectErrorSource
Convert a return code to a ConnectError
.
Message types
The various types of messages.
CONNECT | |
CONNACK | |
PUBLISH | |
PUBACK | |
PUBREC | |
PUBREL | |
PUBCOMP | |
SUBSCRIBE | |
SUBACK | |
UNSUBSCRIBE | |
UNSUBACK | |
PINGREQ | |
PINGRESP | |
DISCONNECT |
Enum MsgType | |
Eq MsgType | |
Ord MsgType | |
Show MsgType | |
SingI MsgType DISCONNECT | |
SingI MsgType PINGRESP | |
SingI MsgType PINGREQ | |
SingI MsgType UNSUBACK | |
SingI MsgType UNSUBSCRIBE | |
SingI MsgType SUBACK | |
SingI MsgType SUBSCRIBE | |
SingI MsgType PUBCOMP | |
SingI MsgType PUBREL | |
SingI MsgType PUBREC | |
SingI MsgType PUBACK | |
SingI MsgType PUBLISH | |
SingI MsgType CONNACK | |
SingI MsgType CONNECT | |
SingKind MsgType (KProxy MsgType) | |
SDecide MsgType (KProxy MsgType) |
toMsgType' :: SomeMessage -> MsgTypeSource
Determine the MsgType
of a SomeMessage
.
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 Message
s.
toSMsgType :: SingI t => Message t -> SMsgType tSource
withSomeSingI :: MsgType -> (forall t. SingI t => SMsgType t -> r) -> rSource
Helper to generate both an implicit and explicit singleton.
data family Sing a