@@ -140,28 +140,16 @@ inline bool IsWrapperType(const FieldDescriptor* descriptor) {
140140 descriptor->message_type ()->file ()->name () == " google/protobuf/wrappers.proto" ;
141141}
142142
143- inline bool IsProto2 (const FileDescriptor* descriptor) {
144- return descriptor->syntax () == FileDescriptor::SYNTAX_PROTO2;
145- }
146-
147143inline bool SupportsPresenceApi (const FieldDescriptor* descriptor) {
148144 // Unlike most languages, we don't generate Has/Clear members for message
149145 // types, because they can always be set to null in C#. They're not really
150146 // needed for oneof fields in proto2 either, as everything can be done via
151- // oneof case, but we follow the convention from other languages. Proto3
152- // oneof fields never have Has/Clear members - but will also never have
153- // the explicit optional keyword either.
154- //
155- // None of the built-in helpers (descriptor->has_presence() etc) describe
156- // quite the behavior we want, so the rules are explicit below.
157-
158- if (descriptor->is_repeated () ||
159- descriptor->type () == FieldDescriptor::TYPE_MESSAGE) {
147+ // oneof case, but we follow the convention from other languages.
148+ if (descriptor->type () == FieldDescriptor::TYPE_MESSAGE) {
160149 return false ;
161150 }
162- // has_optional_keyword() has more complex rules for proto2, but that
163- // doesn't matter given the first part of this condition.
164- return IsProto2 (descriptor->file ()) || descriptor->has_optional_keyword ();
151+
152+ return descriptor->has_presence ();
165153}
166154
167155inline bool RequiresPresenceBit (const FieldDescriptor* descriptor) {
0 commit comments