Re: [PATCH] Display non-present fields with TextFormat.

174 views
Skip to first unread message

Brenden Matthews

unread,
Nov 23, 2010, 8:18:22 PM11/23/10
to prot...@googlegroups.com
On Tue, Nov 23, 2010 at 5:04 PM, Brenden Matthews <bre...@diddyinc.com> wrote:
Greetings,

One of the best features of protocol buffers is the notion of presence.  Another great feature is the ability to do 'message.PrintDebugString()'.  One problem, however, is that fields which are not present do not get displayed when printing the debug string.

Proposed solution: add an optional parameter to display optional fields and their default values (if applicable) even when they aren't present.

Attached is a patch which implements this.

Please provide comments/suggestions, and let me know if this is the right place for this.

I also rushed things a bit, and the first patch has a mistake.  Here is a fixed version of it.
0001-Display-non-present-fields-with-TextFormat.patch

Kenton Varda

unread,
Nov 23, 2010, 10:45:34 PM11/23/10
to Brenden Matthews, prot...@googlegroups.com
Hi Brenden,

Thanks for your interest in improving protocol buffers.  I can see how this option would be useful to some people.  Unfortunately, there are a lot of options that different people find useful, and if we implemented all of them, we'd end up with a very boated library that no one wants to use.  Thus, depressingly, half of my job as the maintainer of protocol buffers is refusing feature requests and contributions.  I even have to reject contributions from other Google employees on a daily basis.

It is actually pretty easy to write a custom TextFormat implementation with whatever modifications you want.  The TextFormat code itself does not depend on any internal interfaces.  Also, you can reuse the code to format individual values by calling TextFormat::PrintFieldValue().  So, what I generally tell people who want to change TextFormat is to write your own class similar to TextFormat that implements your alternative encoding.  I think that would be appropriate in this case.

Sorry.

On Tue, Nov 23, 2010 at 5:04 PM, Brenden Matthews <bre...@diddyinc.com> wrote:
Greetings,

One of the best features of protocol buffers is the notion of presence.  Another great feature is the ability to do 'message.PrintDebugString()'.  One problem, however, is that fields which are not present do not get displayed when printing the debug string.

Proposed solution: add an optional parameter to display optional fields and their default values (if applicable) even when they aren't present.

Attached is a patch which implements this.

Please provide comments/suggestions, and let me know if this is the right place for this.

--
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.

Christoph Heindl

unread,
Dec 22, 2011, 8:25:26 AM12/22/11
to prot...@googlegroups.com
Hi Brenden,

In case you are in interested, I've worked on an alternative approach to display non-present fields in text-formatting. It uses the reflection API and applies default values to empty fields where applicable. Read on:


Best,
Christoph
Reply all
Reply to author
Forward
0 new messages