Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull most active branch #65

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
937ac03
Upgrade dependencies to the latest
ghaskins Feb 18, 2016
bcecf85
Convert to private release in prep for deployment to clojars
ghaskins Feb 18, 2016
183413f
Update project name
ghaskins Feb 18, 2016
aaf5b5b
Update README.md
ghaskins Feb 18, 2016
5345014
Manage the minimum java compatibility to remain compatible with OBC JRE
ghaskins Feb 18, 2016
c5a53a3
Merge branch 'develop' of github.com:ghaskins/clojure-protobuf into d…
ghaskins Feb 18, 2016
9f85e18
Add lein-release support for deploying to clojars
ghaskins Feb 18, 2016
ee93448
Add repository info
ghaskins Feb 18, 2016
1fce098
More clojars tweaking
ghaskins Feb 18, 2016
ee56479
lein-release plugin: preparing 0.1 release
ghaskins Feb 18, 2016
e178db9
lein-release plugin: bumped version from 0.1 to 0.2-SNAPSHOT for next…
ghaskins Feb 18, 2016
ce37bd3
Upgrade to proto3
ghaskins May 17, 2016
1f73a0f
lein-release plugin: preparing 0.2 release
ghaskins May 17, 2016
d3861f1
lein-release plugin: bumped version from 0.2 to 0.3-SNAPSHOT for next…
ghaskins May 17, 2016
f512119
Update to protobuf-3-beta3
ghaskins Jun 29, 2016
0f74b59
Version v0.3
ghaskins Jun 29, 2016
6d8a453
Prepare for v0.4 development
ghaskins Jun 29, 2016
eb2b98f
Upgrade to v3.0.2 released protobuf
ghaskins Sep 22, 2016
6406f40
Version 3.0.2-1
ghaskins Sep 22, 2016
f01e380
Prepare for v3.0.2-2 development
ghaskins Sep 22, 2016
ac86eb2
Upgrade to java 1.8
ghaskins Sep 22, 2016
db71440
Release v3.0.2-2
ghaskins Sep 22, 2016
9b8e20c
moved to protobuf version 3.1.0
shark8me May 16, 2017
e14cea4
Merge pull request #2 from shark8me/protobuf-3.1.0
ghaskins May 23, 2017
ab6dc56
Release v3.1.0-1
ghaskins May 23, 2017
cf4cacd
Prepare for v3.1.0-2 development
ghaskins May 23, 2017
c70ad04
Upgrade to protobuf v3.3.1
ghaskins May 23, 2017
5acd563
Release v3.3.1-1
ghaskins May 23, 2017
0ef68ad
Prepare for v3.3.1-2 development
ghaskins May 23, 2017
0a7e894
Upgrade to protobuf v3.4.0
ghaskins Sep 1, 2017
e2a16d3
Release v3.4.0-1
ghaskins Sep 1, 2017
b9c386e
Prepare for v3.4.0-2 development
ghaskins Sep 1, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 5 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`:

Expand All @@ -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:

Expand Down Expand Up @@ -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))
=> #<byte[] [B@7cbe41ec>

(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).
27 changes: 12 additions & 15 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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)
255 changes: 255 additions & 0 deletions src/flatland/protobuf/Extensions.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.