net-mqtt 0.8.2.0 → 0.8.2.1
raw patch · 8 files changed
+62/−13 lines, 8 filesdep ~attoparsecPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: attoparsec
API changes (from Hackage documentation)
Files
- Changelog.md +11/−0
- README.md +7/−1
- net-mqtt.cabal +8/−6
- src/Network/MQTT/Topic.hs +4/−3
- src/Network/MQTT/Types.hs +3/−2
- test/Example1.hs +12/−0
- test/Example2.hs +16/−0
- test/Spec.hs +1/−1
Changelog.md view
@@ -1,5 +1,16 @@ # Changelog for net-mqtt +## 0.8.2.1++A fix allowing the filter to wildcards to match their parent as per+spec.++This is not very intuitive and kind of seems like a bad idea, but [the+spec](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718107)+says this is how it works.++Thanks to Noah Halford.+ ## 0.8.2.0 Added `OrderedCallback` and `OrderedLowLevelCallback` to guarantee
README.md view
@@ -7,16 +7,22 @@ ### Publish ```haskell+import Network.MQTT.Client+import Network.URI (parseURI)+ main :: IO () main = do let (Just uri) = parseURI "mqtt://test.mosquitto.org"- mc <- connectURI mqttConfig{} uri+ mc <- connectURI mqttConfig uri publish mc "tmp/topic" "hello!" False ``` ### Subscribe ```haskell+import Network.MQTT.Client+import Network.URI (parseURI)+ main :: IO () main = do let (Just uri) = parseURI "mqtt://test.mosquitto.org"
net-mqtt.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.6.+-- This file has been generated from package.yaml by hpack version 0.34.7. -- -- see: https://github.com/sol/hpack name: net-mqtt-version: 0.8.2.0+version: 0.8.2.1 synopsis: An MQTT Protocol Implementation. description: Please see the README on GitHub at <https://github.com/dustin/mqtt-hs#readme> category: Network@@ -39,7 +39,7 @@ build-depends: QuickCheck >=2.12.6.1 && <2.15 , async >=2.2.1 && <2.3- , attoparsec >=0.13.2 && <0.14+ , attoparsec >=0.13.2 && <0.15 , attoparsec-binary >=0.2 && <1.0 , base >=4.7 && <5 , binary >=0.8.5 && <0.9@@ -66,7 +66,7 @@ build-depends: QuickCheck >=2.12.6.1 && <2.15 , async >=2.2.1 && <2.3- , attoparsec >=0.13.2 && <0.14+ , attoparsec >=0.13.2 && <0.15 , attoparsec-binary >=0.2 && <1.0 , base >=4.7 && <5 , binary >=0.8.5 && <0.9@@ -94,7 +94,7 @@ build-depends: QuickCheck >=2.12.6.1 && <2.15 , async >=2.2.1 && <2.3- , attoparsec >=0.13.2 && <0.14+ , attoparsec >=0.13.2 && <0.15 , attoparsec-binary >=0.2 && <1.0 , base >=4.7 && <5 , binary >=0.8.5 && <0.9@@ -117,6 +117,8 @@ type: exitcode-stdio-1.0 main-is: Spec.hs other-modules:+ Example1+ Example2 Paths_net_mqtt hs-source-dirs: test@@ -125,7 +127,7 @@ HUnit , QuickCheck >=2.12.6.1 && <2.15 , async >=2.2.1 && <2.3- , attoparsec >=0.13.2 && <0.14+ , attoparsec >=0.13.2 && <0.15 , attoparsec-binary >=0.2 && <1.0 , base >=4.7 && <5 , binary >=0.8.5 && <0.9
src/Network/MQTT/Topic.hs view
@@ -69,9 +69,10 @@ match (Filter pat) (Topic top) = cmp (splitOn "/" pat) (splitOn "/" top) where- cmp [] [] = True- cmp [] _ = False- cmp _ [] = False+ cmp [] [] = True+ cmp [] _ = False+ cmp ["#"] [] = True+ cmp _ [] = False cmp ["#"] (t:_) = not $ "$" `isPrefixOf` t cmp (p:ps) (t:ts) | p == t = cmp ps ts
src/Network/MQTT/Types.hs view
@@ -30,6 +30,7 @@ import Control.Applicative (liftA2, (<|>)) import Control.Monad (replicateM, when) import Data.Attoparsec.Binary (anyWord16be, anyWord32be)+import qualified Data.Attoparsec.ByteString as AS import qualified Data.Attoparsec.ByteString.Lazy as A import Data.Binary.Put (putWord32be, runPut) import Data.Bits (Bits (..), shiftL, testBit, (.&.), (.|.))@@ -276,7 +277,7 @@ parseProperties Protocol311 = pure mempty parseProperties Protocol50 = do len <- decodeVarInt- either fail pure . A.parseOnly (A.many' parseProperty) =<< A.take len+ either fail pure . AS.parseOnly (A.many' parseProperty) =<< A.take len -- | MQTT Protocol Levels data ProtocolLevel = Protocol311 -- ^ MQTT 3.1.1@@ -717,7 +718,7 @@ a <- subp content pure (pid, props, a) - where subp = either fail pure . A.parseOnly p+ where subp = either fail pure . AS.parseOnly p parseSubscribe :: ProtocolLevel -> A.Parser MQTTPkt parseSubscribe prot = do
+ test/Example1.hs view
@@ -0,0 +1,12 @@+{-# LANGUAGE OverloadedStrings #-}++module Example1 where++import Network.MQTT.Client+import Network.URI (parseURI)++main :: IO ()+main = do+ let (Just uri) = parseURI "mqtt://test.mosquitto.org"+ mc <- connectURI mqttConfig uri+ publish mc "tmp/topic" "hello!" False
+ test/Example2.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE OverloadedStrings #-}++module Example2 where++import Network.MQTT.Client+import Network.URI (parseURI)++main :: IO ()+main = do+ let (Just uri) = parseURI "mqtt://test.mosquitto.org"+ mc <- connectURI mqttConfig{_msgCB=SimpleCallback msgReceived} uri+ print =<< subscribe mc [("tmp/topic1", subOptions), ("tmp/topic2", subOptions)] []+ waitForClient mc -- wait for the the client to disconnect++ where+ msgReceived _ t m p = print (t,m,p)
test/Spec.hs view
@@ -81,7 +81,7 @@ testTopicMatching :: [TestTree] testTopicMatching = let allTopics = ["a", "a/b", "a/b/c/d", "b/a/c/d", "$SYS/a/b", "a/$SYS/b"]- tsts = [("a", ["a"]), ("a/#", ["a/b", "a/b/c/d"]),+ tsts = [("a", ["a"]), ("a/#", ["a", "a/b", "a/b/c/d"]), ("+/b", ["a/b"]), ("+/+/c/+", ["a/b/c/d", "b/a/c/d"]), ("+/+/b", []),