Created
May 15, 2018 12:37
-
-
Save ghaskins/ea35fb5e2376b749d18f7de388698229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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