On Mon, Dec 7, 2009 at 10:57 AM, Tim <tim.es...@gmail.com> wrote:

> We are currently using protobuf on our project and it is great, but
> there are a few things we are needing to do manually which seem like
> they could be easily code generated and supported natively by the
> protobuf objects.  Any chance of the following features being added
> in?  (Or maybe they're already in and I just don't realize it..)
> 1)  Comparison function.  operator== function for C++, compareTo for
> Java.  We use protobuf objects as our underlying object store since
> our application is just a means of exporting data from an underlying
> library.  We read data in from that library, put it directly into
> protobufs, and then send it off.  However, we need to be able to
> easily determine if the data changed between calls to the underlying
> library.  Having an operator== function would solve this for us.  It
> seems like this would be useful to others as well.

You can implement comparison in a general way using reflection.  We chose
not to make it part of the generated code because the generated code is far
too big already, and we find that equality on messages is not used very

Another thing you could do which might be faster is serialize the message
and compare the raw bytes.  As long as the message contains no unknown
fields, it will be serialized in canonical order.  You can use
DiscardUnknownFields() in C++ to remove all unknown fields from the message.

> 2)  Helper function for enums to go to and from string (similar to how
> the new Java-style enums allow you to call valueOf to go from String
> to Enum, and toString to go from Enum to String).  This would be
> extremely useful for us to have the capability in C++, and it seems
> like this could be very easily code-generated.

You can do this with descriptors.

In C++, MyEnumType_descriptor() returns a const EnumDescriptor*, which is
documented here:



You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to