A Java/Clojure library for parsing Google Protocol Buffers proto3
Add the gprotbuf jar to your dependencies.
import gprotbuf.GPBParser;
final Object ast = GPBParser.instance().parse("syntax = \"proto3\";
message M1 {
string str1 = 1;
string str2 = 2;
}
");
if (!GPBParser.instance().isFailure(ast)) { //do parsing
System.out.println(GPBParser.instance().transform(ast)); //transform/clean the ast and validate structure
}
((:message "M1" ([:field "string" "str1" 1] [:field "string" "str2" 2])))
Add the following line to your leinigen dependencies:
[gprotbuf "0.1.0-SNAPSHOT"]
=> (use 'gprotbuf.core)
=> (require '[instaparse.core :as insta])
nil
=> (def proto-file
"syntax = \"proto3\";
message M1 {
string str1 = 1;
string str2 = 2;
}
")
nil
=> (let [ast (parse proto-file)] ;do parsing
(when (not (insta/failure? ast))
(ast->clj ast))) ;transform/clean the ast and validate structure
((:message "M1" ([:field "string" "str1" 1] [:field "string" "str2" 2])))
The returned value is a data structure in the hiccup format.
Copyright © 2017 FIXME
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.