Skip to content

Instantly share code, notes, and snippets.

@minimal
Last active August 29, 2015 14:08
Show Gist options
  • Save minimal/8d5f70af32b62c12e568 to your computer and use it in GitHub Desktop.
Save minimal/8d5f70af32b62c12e568 to your computer and use it in GitHub Desktop.
(ns protobuf-exp.core
(:require [flatland.protobuf.core :as pb])
(:import pi.Pages$Page))
(def Page (pb/protodef Pages$Page))
(def p (pb/protobuf Page :id 1 :url "http://blah.com" :description "I am a protobuf"))
(defn write-to-file [proto path]
(with-open [myout (clojure.java.io/output-stream path)]
(.write myout (pb/protobuf-dump proto))))
(defn load-from-file [path]
(with-open [stream (clojure.java.io/input-stream path)]
(pb/protobuf-load-stream Page stream)))
(comment
(assoc p :classified :CLASSIFIED)
#_=> {:classified :classified,
:description "I am a protobuf",
:id 1,
:url "http://blah.com"}
)
package pi;
message Page {
required int32 id = 1;
required string url = 2;
required string description = 3;
repeated string keywords = 5;
optional float price = 6;
enum ClassifiedType {
CLASSIFIED = 0;
NOT_CLASSIFIED = 1;
UNCLASSIFIABLE = 2;
}
optional ClassifiedType classified = 4 [default = NOT_CLASSIFIED];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment