I was trying to populate and deserialize following message to string:

message SampleSubMessage{
 repeated string str = 1;
 repeated fixed32 val = 2;

message SampleMessage { 
 repeated SampleSubMessage sub = 1; 

I had already set the SetUseShortRepeatedPrimitives to true before 
deserializing the message to string.
However in the output string only integer values were printed in "list 
values" format.

sub {
  str: ""
  str: "4"
  val: [34, 45]
sub {
  str: "2"
  str: "7"
  val: [67]
sub {
  str: "3"

On further investigation i found that follwing code explicitely excludes 
strings and message fields for converting to string.


void TextFormat::Printer::PrintField(const Message& message,
                                     const Reflection* reflection,
                                     const FieldDescriptor* field,
                                     TextGenerator& generator) const {
  if (use_short_repeated_primitives_ &&
      field->is_repeated() &&
*      field*
*->cpp_type() != FieldDescriptor::CPPTYPE_STRING &&      field->cpp_type() 
!= FieldDescriptor::CPPTYPE_MESSAGE*) {
    PrintShortRepeatedField(message, reflection, field, generator);

Could someone please help me understand the reason for this exclusion.

Thank you

Himanshu Agarwal


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 http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to