let serve _ r w =
let rec loop r w =
Reader.read_line r >>= function
| `Eof -> return ()
| `Ok s ->
(match (parse s) with
| Some (Get k) -> get k w
| Some (Set (k, v)) -> set k v w
| Some (Append (k, v)) -> append k v w
| Some (Strlen k) -> strlen k w
| None -> Writer.write_line w ("Error: could not parse " ^ s));
loop r w
in
loop r w