Skip to content

Instantly share code, notes, and snippets.

@ghaskins
Created May 15, 2018 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghaskins/ea35fb5e2376b749d18f7de388698229 to your computer and use it in GitHub Desktop.
Save ghaskins/ea35fb5e2376b749d18f7de388698229 to your computer and use it in GitHub Desktop.
(defn- ->parsefn [type]
(let [name (-> (str "cis->" type)
symbol)
f (-> (str ".read" type)
symbol)]
(intern *ns* name #(f %))))
(defn- ->writefn [type]
(let [name (-> (str "write-" type)
symbol)
f (-> (str ".write" type)
symbol)]
(intern *ns* name
(fn [tag value os]
(when value
(f os tag value))))))
(defn- ->sizefn [type]
(let [name (-> (str "size-" type)
symbol)
f (-> (str "CodedOutputStream/compute" type "Size")
symbol)]
(intern *ns* name
(fn [tag value]
(if value
(f tag value)
0)))))
(def scalars
["Bool"
"Bytes"
"Double"
"Enum"
"Fixed32"
"Fixed64"
"Float"
"Int32"
"Int64"
"SFixed32"
"SFixed64"
"SInt32"
"SInt64"
"String"
"UInt32"
"UInt64"])
(doseq [scalar scalars]
(->parsefn scalar)
(->writefn scalar)
(->sizefn scalar))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment