clojusc / protobuf

A Clojure interface to Google's protocol buffers
https://clojusc.github.io/protobuf/
Eclipse Public License 1.0
73 stars 8 forks source link

com.google.protobuf.Descriptors$EnumValueDescriptor isn't handled #22

Closed oubiwann closed 6 years ago

oubiwann commented 6 years ago

Update: The example below has been edited to work with the most recent API.

Looks like we have a missing feature in the Clojure API ... (probably the Java wrapper?)

To see this problem, just fire up the REPL and:

[protobuf.dev] λ=> (require '[protobuf.core :as protobuf])
nil
[protobuf.dev] λ=> (import '(protobuf.examples.tutorial AddressBookProtos$AddressBook))
protobuf.examples.tutorial.AddressBookProtos$AddressBook
[protobuf.dev] λ=> (def AddressBook (protobuf/create AddressBookProtos$AddressBook))
#'protobuf.dev/AddressBook
[protobuf.dev] λ=> (pprint (protobuf/->schema AddressBook))
{:type :struct,
 :name "tutorial.AddressBook",
 :fields
 {:people
  {:type :list,
   :values
   {:type :struct,
    :name "tutorial.Person",
    :fields
    {:name {:type :string},
     :id {:type :int},
     :email {:type :string},
     :phones
     {:type :list,
      :values
      {:type :struct,
       :name "tutorial.Person.PhoneNumber",
       :fields
       {:number {:type :string},
        :type
        {:type :enum,
         :values #{:home :work :mobile},
         :default
         #object[com.google.protobuf.Descriptors$EnumValueDescriptor 0x1a07f7ad "home"]}}}}}}}}}
nil
[protobuf.dev] λ=> (get-in (protobuf/->schema AddressBook) 
                           [:fields :people :values 
                            :fields :phones :values 
                            :fields :type :default])
#object[com.google.protobuf.Descriptors$EnumValueDescriptor 0x1a07f7ad "home"]

This is coming from the following proto file definition:

syntax = "proto2";

package tutorial;

option java_package = "protobuf.examples.tutorial";
option java_outer_classname = "AddressBookProtos";

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phones = 4;
}

message AddressBook {
  repeated Person people = 1;
}
oubiwann commented 6 years ago

Fixed in 40d08eb73969b36624ecf681a63256a286680790.