 (defn cmd-gets-keys [decoded]
   (clojure.string/split (first (rest decoded)) #" "))
 
-(defn debug-response [ch msg r]
-  (do 
-    (println msg r)
-    (map #(enqueue ch %) r)))
 
-(defn test-handle [ch ci cmd]
+(defn memcache [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" ""]))
+      "set" (enqueue ch ["STORED"]) 
+      "get" (do (enqueue ch ["VALUE" "abc" "0" "3" "123"]) (enqueue ch ["END"]))
+      "gets" (do (enqueue ch ["VALUE" "abc" "0" "3" "123"]) (enqueue ch ["END"]))
       (enqueue ch "error")))
 
 
 (defn handler
   [ch ci]
-  (receive-all ch (partial test-handle ch ci)))
+  (receive-all ch (partial memcache ch ci)))
 
-
-;(def s (start-tcp-server handler {:port 10000 :frame MEMCACHE}))
+(defn start-server [port]
+  (start-tcp-server handler {:port port :frame MEMCACHE}))

  (println (format "b->h '%s'" body))
  (first body))

(defn memcache-pre-encode [req]
  (println (format "memcache-pre-encode '%s'" req))
  req)

(defn memcache-post-decode [res]
  (println (format "memcache-post-decode '%s'" res))
  res)

(defcodec MEMCACHE (compile-frame 
                     (header CMD h->b b->h)

  (println (format "body->h: '%s' '%s'" body (first body)))
  (first body))

(defn h->b [hd] 
  "Called when decoding. Determines how to construct the body."
  (println (format "header h->b: '%s'" hd))
    (case hd
      "gets"   GETS
      "get"    GET
      "set"    SET
      "VALUE"  VALUE
      "STORED" STORED
      "END"    END
          ERRC))

(defn b->h 
  "Called when encoding. Determines the header that is generated."
