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

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

(defn handle [ch ci cmd]
    (println "Processing command: " (first cmd) " from " ci)
    (condp = (first cmd)
      "SET" (do (println "doing enqueue put") (enqueue ch ["STORED"]))
      "GET" (enqueue ch "got get\r\n")
      "GETS" (enqueue ch "got mget\r\n")
      (enqueue ch "error")))


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


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

(def TRM-DATA-BLOCK (string :utf-8 :suffix "\r\n"))
(def C (string :utf-8 :delimiters " "))
(def K (string :utf-8 :delimiters " "))
(def KV (string :utf-8 :prefix " " :suffix "\r\n"))
(def CR (string :utf-8 :delimiters ["\r\n"]))

(defcodec SET ["SET" CR])
(defcodec STORED ["STORED\r\n"])
;STORED\r\n

(defcodec GET ["GET" CR])
(defcodec GETS ["GETS" CR])
(defcodec VALUE ["VALUE" CR CR])
(defcodec END ["END\r\n"])

; to test (decode GET-REPLY gets_test_b)
; (decode GET-REPLY (encode GET-REPLY [["VALUE" "abc" "123"] ["VALUE" "abc" "123"]])) 
; (defcodec GET-REPLY (repeated VALUE :prefix :none :delimiters ["END\r\n"]))

;VALUE <key> <flags> <bytes> [<cas unique>]\r\n
;<data block>\r\n
