Last active
August 29, 2015 14:08
-
-
Save minimal/8d5f70af32b62c12e568 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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