 
 ;(def sb (java.nio.ByteBuffer/wrap (.getBytes "STORED\r\nVALUE abc\r\n123\r\n")))
 ;(defcodec X ["STORED" CR C CR CR "END" CR])
-;(def get_test_b (java.nio.ByteBuffer/wrap (.getBytes "VALUE abc\r\n123\r\nEND\r\n")))
+;(def end_test_b (java.nio.ByteBuffer/wrap (.getBytes "END\r\n")))
+
+;(def get_test_b (java.nio.ByteBuffer/wrap (.getBytes "VALUE abc\r\n123\r\n")))
 ;(def gets_test_b (java.nio.ByteBuffer/wrap (.getBytes "VALUE abc\r\n123\r\nVALUE cde\r\n456\r\nEND\r\n")))
 ;(def value_test_b (java.nio.ByteBuffer/wrap (.getBytes "VALUE abc\r\n123\r\n")))
 ;(def values_test_b (java.nio.ByteBuffer/wrap (.getBytes "VALUE abc\r\n123\r\nVALUE cde\r\n456\r\n")))

(defcodec CMDS
          (header C
                  (fn [h]
                    (case h
                      "SET" SET
                      "GET" GET
                      "GETS" GETS
                      "STORED" (do (println "stored") GET-REPLY)
                      (do (println "err") ERRC)))
                  first))


(defn cmd-gets-keys [decoded]
  (extract-cmd-args decoded (fn [v] v)))

(defn debug-response [ch msg r]
  (do 
    (println msg r)
    (map #(enqueue ch %) r)))

(defn test-handle [ch ci cmd]
    (println "Processing command: " (first cmd) " from " ci)
    (condp = (first cmd)
      "SET" (enqueue ch ["STORED"]) 
      "GET" (do (enqueue ch ["VALUE" "abc" "123"]) (enqueue ch ["END"]))
      "GETS" (do (enqueue ch ["VALUE" "abc" "123"]) (enqueue ch ["END"]))
      (enqueue ch "error")))


(defn handler
  [ch ci]
  (receive-all ch (partial test-handle ch ci)))


;(def s (start-tcp-server handler {:port 10000 :frame CMDS}))
