[protobuf] EnumValueDescriptor doesn't provide toString()?

56 views
Skip to first unread message

Christopher Smith

unread,
May 10, 2010, 12:49:00 PM5/10/10
to prot...@googlegroups.com
I noticed EnumValueDescriptor uses the default toString() method. Why not override it to call getFullName()?

--Chris

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Kenton Varda

unread,
May 10, 2010, 11:32:50 PM5/10/10
to Christopher Smith, prot...@googlegroups.com
I don't think we should add toString() to any of the descriptor classes unless we are going to implement it for *all* of them in some consistent way.  If we fill them in ad-hoc then they may be inconsistent, and we may not be able to change them to make them consistent without breaking users.

Christopher Smith

unread,
May 11, 2010, 12:17:57 AM5/11/10
to Kenton Varda, prot...@googlegroups.com
Actually, toString() seems to work for me for every other value I get from a dynamic message *except* enums.

--Chris

Kenton Varda

unread,
May 17, 2010, 3:35:59 PM5/17/10
to Christopher Smith, prot...@googlegroups.com
Right, because none of the other field value types are descriptors.  I see your point -- since getField() returns an Object, it would certainly be nice to be able to call toString() on it without knowing the type.  But, it's also important that EnumValueDescriptor be consistent with other descriptor classes, so we want to be careful not to mess up that consistency.

Instead of calling toString(), you could call TextFormat.printFieldToString() to get a string representation of the field, although it will include the field name.

Christopher Smith

unread,
May 17, 2010, 3:53:22 PM5/17/10
to Kenton Varda, prot...@googlegroups.com
I grok the problem now. This is the only descriptor that is also a value. Probably should have a method/visitor specifically for getting the value string of an object that isn't implemented by descriptors.

--Chris
Reply all
Reply to author
Forward
0 new messages