MODIFIED. This code now works.
I am trying to follow the example here:
https://github.com/flatland/clojure-protobuf
I created a new project thus:
lein new protobuf
Changing directory into protobuf, I added inside /resources/proto/ the example.proto file with these contents:
option java_package = "com.example";
package Example;
message Person {
   required int32  id    = 1;
   required string name  = 2;
   optional string email = 3;
   repeated string likes = 4;
}
My project file looks like this. The only difference from the example in the url above is that I modified to 1.5.1.
(defproject org.flatland/protobuf "0.8.2-SNAPSHOT"
 :description "Clojure-protobuf provides a clojure interface to Google's protocol buffers."
 :license {:name "Eclipse Public License"
        :url "http://www.eclipse.org/legal/epl-v10.html"}
 :url "https://github.com/flatland/clojure-protobuf"
 :dependencies [[org.clojure/clojure "1.5.1"]
             [org.flatland/protobuf "0.7.1"] 
             [org.flatland/useful "0.11.1"]
             [org.flatland/schematic "0.1.2"]
             [org.flatland/io "0.3.0"]
             [ordered-collections "0.4.2"]]
 :plugins [[lein-protobuf "0.1.1"]]
 :aliases {"testall" ["with-profile" "dev,default:dev,1.3,default:dev,1.5,default" "test"]}
 :profiles {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
         :1.5 {:dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]}
         :dev {:dependencies [[gloss "0.2.2"]]}}
 :repositories {"sonatype-snapshots" {:url "http://oss.sonatype.org/content/repositories/snapshots"
                                   :snapshots true
                                   :releases {:checksum :fail :update :always}}}
 :checksum-deps true
 :java-source-paths ["src"])
I then did a
lein protobuf
Now I entered the REPL
lein repl
I tried the first command:
(use 'flatland.protobuf.core)
Then I tried the next line
(import com.example.Example$Person)
Then the rest of the example works fine.
It looks like clojusc/protobuf is a better maintained fork. Project readme contains a straightforward protobuf example. It shows how to use the protoc compiler and java interop clearly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With