Skip to content

Instantly share code, notes, and snippets.

@carllerche
Created February 17, 2012 22:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carllerche/bfedfcc1e31a905bcbec to your computer and use it in GitHub Desktop.
Save carllerche/bfedfcc1e31a905bcbec to your computer and use it in GitHub Desktop.
(defautomata netstring
(word (* any ? bytes-remaining $ track-word % print-word))
(frame (+ digit $ track-size) ":" word)
(start (* frame ",") frame))
(defn- parse-buffer [buf]
(loop [cs (initial-state netstring)
i 0
size 0
word []
char (get-char buf i)]
(defexecution netstring [i size word]
(bytes-remaining (> size 0))
(track-size (next-action i (+ size (char-to-int char)) word))
(track-word (next-action i size (conj word char)))
(print-word (println word))
(recur cs (inc i) size char))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment