On Wed, Jan 4, 2017 at 9:07 AM, Dan Becker <danbecke...@gmail.com> wrote:

>
> I'm using DebugString() in C++ to pretty print google protobuf messages
> read in binary form, and converted using ParseFromIstream().
>
> Its only printing the type name at the top level, and for all levels, its
> just printing the type number.
>
> I am using extensions. is that the reason for the refusal to print
> typenames for lower levels? For example, the debug output looks like:
>
>
> type: FOO1234 {
>    1 {
>      1 {
>        1: 1
>      }
>      2: "string"
>    }}
>
> If I create the message from scratch on the stack, usingMutableExtension, 
> mutable_*, and set_* methods,
> and then use DebugString to print the message I get the full type names.
>
> How can I get the message read in binary form to display the typenames in the 
> debugString output?
>
> The C++ compiler is smart enough to strip out unused extension message
types and that's why DebugString() prints numbers rather than type names.
To prevent that from happening you need to use the extension message type
explicitly somewhere in your code. For example, suppose you have this
definition:
message Foo {
  extensions 1 to 1000;
}

message Bar {
  extend Foo {
    optional Bar foo_bar = 1;
  }
}

you can invoke Bar::descriptor() anywhere in your code path (make sure it's
actually executed), and that will force the Bar type to be linked in and
after that a Foo message containing a Bar extension should be correctly
formatted in DebugString().


> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to