protobuf.Text icon indicating copy to clipboard operation
protobuf.Text copied to clipboard

Generated text format is not readable by text_format lib in other languages.

Open Gateswong opened this issue 4 years ago • 0 comments

I generated a text file through this formatter with the following setups:

Proto

message SomeEntity {
  int64 temporary_id = 1;
  string temporary_name = 2;
}

message SomeRequest {
  SomeEntity entity = 1;
}

C# message object:

var request = new SomeRequest() {
  Entity = new SomeEntity() {
    TemporaryId = 5,
    TemporaryName = "dummy name",
  },
};

I serialized it to text and printed out:

using (StreamWriter writer = new StreamWriter(outputFile, false))
{
    writer.Write(request.ToText());
}

Now the output file looks like this:

entity {
temporary_id: "-5"
temporary_name: "dummy name"
}

I tried to parse this text file in python using text_format, and got the following error:

google.protobuf.text_format.ParseError: 2:15 : 'temporary_id: "-5"': Couldn't parse integer: "-5" 

In fact, the output integer should be: temporary_id: -5 instead of temporary_id: "-5"

Gateswong avatar Jun 05 '21 04:06 Gateswong