aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2016-10-31 18:49:18 -0500
committerDavid Barksdale <amatus@amatus.name>2016-10-31 18:49:18 -0500
commit9f446be952d53009ba585ac64992a9db260d3e4f (patch)
tree03c8a9d20ae12ee7bc8979f2b228f95975d207a1
parentb92b03c0cdf46f97381834837427903f3219c4f5 (diff)
Fix parse-message-types to only consume one msg
-rw-r--r--src/cljs/gnunet_web/message.cljs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/cljs/gnunet_web/message.cljs b/src/cljs/gnunet_web/message.cljs
index cb0d918..275517f 100644
--- a/src/cljs/gnunet_web/message.cljs
+++ b/src/cljs/gnunet_web/message.cljs
@@ -16,7 +16,8 @@
(ns gnunet-web.message
(:require [gnunet-web.encoder :refer [encode-uint16]]
- [gnunet-web.parser :refer [items parser parse-uint16]])
+ [gnunet-web.parser :refer [items parser parse-uint16]]
+ [monads.core :refer [set-state]])
(:require-macros [monads.macros :as monadic]))
(def parse-header
@@ -32,11 +33,14 @@
consume the entire input."
[parser-set]
(monadic/do parser
- [{message-type :message-type} parse-header
+ [{message-type :message-type size :size} parse-header
:let [p (first (filter #(= message-type (:message-type (meta %)))
parser-set))]
:when p
- message p]
+ new-state (items (- size 4))
+ old-state (set-state new-state)
+ message p
+ _ (set-state old-state)]
{:message-type message-type :message message}))
(defn encode-message