wang-xinhong / protobuf

Automatically exported from code.google.com/p/protobuf
Other
0 stars 0 forks source link

PrintFieldValue() fails if the enumvalue is valid. #660

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a message for an enum, but make the enumvalue invalid

What is the expected output? What do you see instead?

I see an Exception casued by test_format.py line 123:
> out.write(field.enum_type.values_by_number[value].name)

Please provide any additional information below.

One might argue that an error is epected, but protobufs are generally 
considered backwards compatible, so if I add a new value to the enum it should 
not cause software running old versions to throw exceptions.

I propose displaying the int value if no enum name can be found.

Original issue reported on code.google.com by matthew....@gmail.com on 7 Aug 2014 at 2:37

GoogleCodeExporter commented 9 years ago
Protobuf provides backward compatibility for wire format, not that we'll 
tolerant arbitrary invalid values thrown to protobuf API.

Here is what we guaranteed for compatibility: If an old server parses data 
produced by a new client and the data contains enum values that are unknown to 
the server, parsing will succeed and these unknown enum values will be stored 
as unknown fields so the actual data is preserved but just that the server will 
see that enum field as not set. This way old server will be able to work with 
new data and we can guarantee all enum values you read from protobuf messages 
to be valid.

Original comment by xiaof...@google.com on 7 Aug 2014 at 5:28