mqtt-hs-1.0.1: A MQTT client library.

Maintainerkoomi+mqtt@hackerspace-bamberg.de
Safe HaskellNone

Network.MQTT.Parser

Contents

Description

Parsers for MQTT messages.

Synopsis

Documentation

type MessageParser a = StateT Word32 Parser aSource

Type of a parser that also keeps track of the remaining length.

message :: Parser SomeMessageSource

Parse any MQTT message.

Fixed Header

mqttHeader :: Parser (MsgType, MqttHeader)Source

Parser for the fixed header part of a MQTT message.

parseRemaining :: Parser Word32Source

Parse the 'remaining length' field that indicates how long the rest of the message is.

Message Body

mqttBody :: MqttHeader -> SMsgType t -> Word32 -> Parser (MessageBody t)Source

mqttBody header msgtype remaining» parses aMessage of type msgtype that is remaining bytes long.

Utility functions

getTopic :: MessageParser TopicSource

Parse a topic name.

mqttText :: MessageParser MqttTextSource

Parse a length-prefixed UTF-8 string.

anyWord16BE :: (Num a, Bits a) => MessageParser aSource

Parse a big-endian 16bit integer.

anyWord8' :: MessageParser Word8Source

A lifted version of attoparsec's anyWord8 that also subtracts 1 from the remaining length.

ctxt :: String -> Parser a -> Parser aSource

take' :: Word32 -> MessageParser ByteStringSource

A lifted version of attoparsec's take that also subtracts the length.

parseLength :: Word32 -> MessageParser ()Source

Subtract n from the remaining length or fail if there is not enough input left.

toQoS :: (Num a, Eq a, Show a, Monad m) => a -> m QoSSource

Convert a number to a QoS. fail if the number can't be converted.