From 9f446be952d53009ba585ac64992a9db260d3e4f Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Mon, 31 Oct 2016 18:49:18 -0500 Subject: Fix parse-message-types to only consume one msg --- src/cljs/gnunet_web/message.cljs | 10 +++++++--- 1 file 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 -- cgit v1.2.3-18-g5258