Skip to content

eliassona/gprotbuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gprotbuf

A Java/Clojure library for parsing Google Protocol Buffers proto3

Usage

Java

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])))        

Clojure

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.

License

Copyright © 2017 FIXME

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published