mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-26 21:04:23 +08:00
protoc-c/c_enum_field.cc: Fix default enum values
From https://developers.google.com/protocol-buffers/docs/proto#optional: If the default value is not specified for an optional element, a type-specific default value is used instead: for strings, the default value is the empty string. For bools, the default value is false. For numeric types, the default value is zero. For enums, the default value is the first value listed in the enum's type definition. This means care must be taken when adding a value to the beginning of an enum value list. Prior to this change, protoc-c set the default enum value to 0, whether or not 0 was the first value listed in the enum's type definition (or if it even was listed at all).
This commit is contained in:
parent
006d69bd84
commit
258eb7d4dc
@ -79,12 +79,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
|
||||
|
||||
(*variables)["name"] = FieldName(descriptor);
|
||||
(*variables)["type"] = FullNameToC(descriptor->enum_type()->full_name());
|
||||
if (descriptor->has_default_value()) {
|
||||
const EnumValueDescriptor* default_value = descriptor->default_value_enum();
|
||||
(*variables)["default"] = FullNameToUpper(default_value->type()->full_name())
|
||||
+ "__" + default_value->name();
|
||||
} else
|
||||
(*variables)["default"] = "0";
|
||||
const EnumValueDescriptor* default_value = descriptor->default_value_enum();
|
||||
(*variables)["default"] = FullNameToUpper(default_value->type()->full_name())
|
||||
+ "__" + default_value->name();
|
||||
(*variables)["deprecated"] = FieldDeprecated(descriptor);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user