diff --git a/README.md b/README.md index cf593b3..e150c95 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,11 @@ clojure-protobuf provides a Clojure interface to Google's [protocol buffers](http://code.google.com/p/protobuf). -Protocol buffers can be used to communicate with other languages over the network, and -they are WAY faster to serialize and deserialize than standard Clojure objects. +Protocol buffers can be used to communicate with other languages over the network, and they are WAY faster to serialize and deserialize than standard Clojure objects. ## Getting started -You'll probably want to use [Leiningen](https://github.com/technomancy/leiningen) with the -[lein-protobuf](https://github.com/flatland/lein-protobuf) plugin for compiling `.proto` files. Add -the following to your `project.clj` file: +Add the dependency to your project.clj - :dependencies [[org.flatland/protobuf "0.7.1"]] - :plugins [[lein-protobuf "0.1.1"]] - -Be sure to replace `"0.6.0"` and `"0.1.1"` with the latest versions listed at -http://clojars.org/protobuf and http://clojars.org/lein-protobuf. - -*Note: lein-protobuf requires at least version 2.0 of Leiningen.* - -## Usage +[![Clojars Project](https://img.shields.io/clojars/v/org.clojars.ghaskins/protobuf.svg)](https://clojars.org/org.clojars.ghaskins/protobuf) Assuming you have the following in `resources/proto/person.proto`: @@ -29,9 +18,9 @@ message Person { } ``` -You can run the following to compile the `.proto` file: +Compile the proto using the protobuf compiler and include the resulting .java code in your project - lein protobuf + protoc --java_out=./ -proto_dir=resources/proto person.proto Now you can use the protocol buffer in Clojure: @@ -60,66 +49,3 @@ Now you can use the protocol buffer in Clojure: A protocol buffer map is immutable just like other clojure objects. It is similar to a struct-map, except you cannot insert fields that aren't specified in the `.proto` file. -## Extensions - -Clojure-protobuf supports extensions to protocol buffers which provide sets and maps using -repeated fields. You can also provide metadata on protobuf fields using clojure syntax. To -use these, you must import the extension file and include it when compiling. For example: - -```proto -import "flatland/protobuf/core/extensions.proto"; - -message Photo { - required int32 id = 1; - required string path = 2; - repeated Label labels = 3 [(set) = true]; - repeated Attr attrs = 4 [(map) = true]; - repeated Tag tags = 5 [(map_by) = "person_id"]; - - message Label { - required string item = 1; - required bool exists = 2; - } - - message Attr { - required string key = 1; - optional string val = 2; - } - - message Tag { - required int32 person_id = 1; - optional int32 x_coord = 2 [(meta) = "{:max 100.0 :min -100.0}"]; - optional int32 y_coord = 3; - optional int32 width = 4; - optional int32 height = 5; - } -} -``` -Then you can access the extension fields in Clojure: - -```clojure -(use 'flatland.protobuf.core) -(import Example$Photo) -(import Example$Photo$Tag) - -(def Photo (protodef Example$Photo)) -(def Tag (protodef Example$Photo$Tag)) - -(def p (protobuf Photo :id 7 :path "/photos/h2k3j4h9h23" :labels #{"hawaii" "family" "surfing"} - :attrs {"dimensions" "1632x1224", "alpha" "no", "color space" "RGB"} - :tags {4 {:person_id 4, :x_coord 607, :y_coord 813, :width 25, :height 27}})) -=> {:id 7 :path "/photos/h2k3j4h9h23" :labels #{"hawaii" "family" "surfing"}...} - -(def b (protobuf-dump p)) -=> # - -(protobuf-load Photo b) -=> {:id 7 :path "/photos/h2k3j4h9h23" :labels #{"hawaii" "family" "surfing"}...} - -(:x-coord (protobuf-schema Tag)) -=> {:max 100.0 :min -100.0} -``` - -## Getting Help - -If you have any questions or need help, you can find us on IRC in [#flatland](irc://irc.freenode.net/#flatland). diff --git a/project.clj b/project.clj index 02ff5c2..cc1d4d6 100644 --- a/project.clj +++ b/project.clj @@ -1,20 +1,17 @@ -(defproject org.flatland/protobuf "0.8.2-SNAPSHOT" +(defproject org.clojars.ghaskins/protobuf "3.4.0-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.4.0"] - [org.flatland/useful "0.9.0"] - [org.flatland/schematic "0.1.0"] + :url "https://github.com/ghaskins/clojure-protobuf" + :javac-options ["-target" "1.8" "-source" "1.8"] + :java-source-paths ["src"] + :lein-release {:deploy-via :clojars} + :dependencies [[org.clojure/clojure "1.8.0"] + [com.google.protobuf/protobuf-java "3.4.0"] + [org.flatland/useful "0.11.5"] + [org.flatland/schematic "0.1.5"] [org.flatland/io "0.3.0"] - [ordered-collections "0.4.0"]] - :plugins [[lein-protobuf "0.4.1"]] + [ordered-collections "0.4.2"] + [gloss "0.2.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.1"]]}} - :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"]) + :checksum-deps true) diff --git a/src/flatland/protobuf/Extensions.java b/src/flatland/protobuf/Extensions.java new file mode 100644 index 0000000..c141191 --- /dev/null +++ b/src/flatland/protobuf/Extensions.java @@ -0,0 +1,255 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: flatland/protobuf/extensions.proto + +package flatland.protobuf; + +public final class Extensions { + private Extensions() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registry.add(flatland.protobuf.Extensions.set); + registry.add(flatland.protobuf.Extensions.map); + registry.add(flatland.protobuf.Extensions.mapBy); + registry.add(flatland.protobuf.Extensions.counter); + registry.add(flatland.protobuf.Extensions.succession); + registry.add(flatland.protobuf.Extensions.mapDeleted); + registry.add(flatland.protobuf.Extensions.mapExists); + registry.add(flatland.protobuf.Extensions.meta); + registry.add(flatland.protobuf.Extensions.nullable); + registry.add(flatland.protobuf.Extensions.nullString); + registry.add(flatland.protobuf.Extensions.nullInt); + registry.add(flatland.protobuf.Extensions.nullLong); + registry.add(flatland.protobuf.Extensions.nullFloat); + registry.add(flatland.protobuf.Extensions.nullDouble); + registry.add(flatland.protobuf.Extensions.nullEnum); + } + public static final int SET_FIELD_NUMBER = 52001; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> set = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + public static final int MAP_FIELD_NUMBER = 52002; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> map = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + public static final int MAP_BY_FIELD_NUMBER = 52003; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.String> mapBy = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.String.class, + null); + public static final int COUNTER_FIELD_NUMBER = 52004; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> counter = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + public static final int SUCCESSION_FIELD_NUMBER = 52005; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> succession = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + public static final int MAP_DELETED_FIELD_NUMBER = 52006; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.String> mapDeleted = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.String.class, + null); + public static final int MAP_EXISTS_FIELD_NUMBER = 52007; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.String> mapExists = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.String.class, + null); + public static final int META_FIELD_NUMBER = 52010; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.String> meta = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.String.class, + null); + public static final int NULLABLE_FIELD_NUMBER = 52020; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> nullable = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + public static final int NULL_STRING_FIELD_NUMBER = 52021; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.String> nullString = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.String.class, + null); + public static final int NULL_INT_FIELD_NUMBER = 52022; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Integer> nullInt = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Integer.class, + null); + public static final int NULL_LONG_FIELD_NUMBER = 52023; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Long> nullLong = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Long.class, + null); + public static final int NULL_FLOAT_FIELD_NUMBER = 52024; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Float> nullFloat = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Float.class, + null); + public static final int NULL_DOUBLE_FIELD_NUMBER = 52025; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Double> nullDouble = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Double.class, + null); + public static final int NULL_ENUM_FIELD_NUMBER = 52026; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Integer> nullEnum = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Integer.class, + null); + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\"flatland/protobuf/extensions.proto\032 go" + + "ogle/protobuf/descriptor.proto:,\n\003set\022\035." + + "google.protobuf.FieldOptions\030\241\226\003 \001(\010:,\n\003" + + "map\022\035.google.protobuf.FieldOptions\030\242\226\003 \001" + + "(\010:/\n\006map_by\022\035.google.protobuf.FieldOpti" + + "ons\030\243\226\003 \001(\t:0\n\007counter\022\035.google.protobuf" + + ".FieldOptions\030\244\226\003 \001(\010:3\n\nsuccession\022\035.go" + + "ogle.protobuf.FieldOptions\030\245\226\003 \001(\010:4\n\013ma" + + "p_deleted\022\035.google.protobuf.FieldOptions" + + "\030\246\226\003 \001(\t:3\n\nmap_exists\022\035.google.protobuf", + ".FieldOptions\030\247\226\003 \001(\t:-\n\004meta\022\035.google.p" + + "rotobuf.FieldOptions\030\252\226\003 \001(\t:1\n\010nullable" + + "\022\035.google.protobuf.FieldOptions\030\264\226\003 \001(\010:" + + "4\n\013null_string\022\035.google.protobuf.FieldOp" + + "tions\030\265\226\003 \001(\t:1\n\010null_int\022\035.google.proto" + + "buf.FieldOptions\030\266\226\003 \001(\021:2\n\tnull_long\022\035." + + "google.protobuf.FieldOptions\030\267\226\003 \001(\022:3\n\n" + + "null_float\022\035.google.protobuf.FieldOption" + + "s\030\270\226\003 \001(\002:4\n\013null_double\022\035.google.protob" + + "uf.FieldOptions\030\271\226\003 \001(\001:2\n\tnull_enum\022\035.g", + "oogle.protobuf.FieldOptions\030\272\226\003 \001(\rB\037\n\021f" + + "latland.protobufB\nExtensions" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.protobuf.DescriptorProtos.getDescriptor(), + }, assigner); + set.internalInit(descriptor.getExtensions().get(0)); + map.internalInit(descriptor.getExtensions().get(1)); + mapBy.internalInit(descriptor.getExtensions().get(2)); + counter.internalInit(descriptor.getExtensions().get(3)); + succession.internalInit(descriptor.getExtensions().get(4)); + mapDeleted.internalInit(descriptor.getExtensions().get(5)); + mapExists.internalInit(descriptor.getExtensions().get(6)); + meta.internalInit(descriptor.getExtensions().get(7)); + nullable.internalInit(descriptor.getExtensions().get(8)); + nullString.internalInit(descriptor.getExtensions().get(9)); + nullInt.internalInit(descriptor.getExtensions().get(10)); + nullLong.internalInit(descriptor.getExtensions().get(11)); + nullFloat.internalInit(descriptor.getExtensions().get(12)); + nullDouble.internalInit(descriptor.getExtensions().get(13)); + nullEnum.internalInit(descriptor.getExtensions().get(14)); + com.google.protobuf.DescriptorProtos.getDescriptor(); + } + + // @@protoc_insertion_point(outer_class_scope) +}