Skip to content

Commit 8b1be51

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Breaking change: lock down visibility for FileDescriptor syntax APIs.
These will become meaningless once we migrate to editions. In the meantime, we've implemented APIs to expose the differences between proto2 and proto3 in terms of the features we plan to release in edition 2023. PiperOrigin-RevId: 517433756
1 parent aaa338b commit 8b1be51

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/google/protobuf/descriptor.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,6 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
752752
bool is_map() const; // shorthand for type() == TYPE_MESSAGE &&
753753
// message_type()->options().map_entry()
754754

755-
// Returns true if this field was syntactically written with "optional" in the
756-
// .proto file. Excludes singular proto3 fields that do not have a label.
757-
bool has_optional_keyword() const;
758-
759755
// Returns true if this field tracks presence, ie. does the field
760756
// distinguish between "unset" and "present with default value."
761757
// This includes required, optional, and oneof fields. It excludes maps,
@@ -920,6 +916,11 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
920916
friend class io::Printer;
921917
friend class compiler::cpp::Formatter;
922918
friend class Reflection;
919+
friend class FieldDescriptorLegacy;
920+
921+
// Returns true if this field was syntactically written with "optional" in the
922+
// .proto file. Excludes singular proto3 fields that do not have a label.
923+
bool has_optional_keyword() const;
923924

924925
// Fill the json_name field of FieldDescriptorProto.
925926
void CopyJsonNameTo(FieldDescriptorProto* proto) const;
@@ -1040,10 +1041,6 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase {
10401041
// Index of this oneof within the message's oneof array.
10411042
int index() const;
10421043

1043-
// Returns whether this oneof was inserted by the compiler to wrap a proto3
1044-
// optional field. If this returns true, code generators should *not* emit it.
1045-
bool is_synthetic() const;
1046-
10471044
// The .proto file in which this oneof was defined. Never nullptr.
10481045
const FileDescriptor* file() const;
10491046
// The Descriptor for the message containing this oneof.
@@ -1080,6 +1077,11 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase {
10801077
// Allows access to GetLocationPath for annotations.
10811078
friend class io::Printer;
10821079
friend class compiler::cpp::Formatter;
1080+
friend class OneofDescriptorLegacy;
1081+
1082+
// Returns whether this oneof was inserted by the compiler to wrap a proto3
1083+
// optional field. If this returns true, code generators should *not* emit it.
1084+
bool is_synthetic() const;
10831085

10841086
// See Descriptor::DebugString().
10851087
void DebugString(int depth, std::string* contents,
@@ -1651,7 +1653,11 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
16511653
// descriptor.proto, and any available extensions of that message.
16521654
const FileOptions& options() const;
16531655

1654-
// Syntax of this file.
1656+
private:
1657+
// With the upcoming release of editions, syntax should not be used for
1658+
// business logic. Instead, the various feature helpers defined in this file
1659+
// should be used to query more targeted behaviors. For example:
1660+
// has_presence, is_closed, requires_utf8_validation.
16551661
enum Syntax
16561662
#ifndef SWIG
16571663
: int
@@ -1662,8 +1668,15 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
16621668
SYNTAX_PROTO3 = 3,
16631669
};
16641670
Syntax syntax() const;
1671+
1672+
// Define a visibility-restricted wrapper for internal use until the migration
1673+
// is complete.
1674+
friend class FileDescriptorLegacy;
1675+
16651676
static const char* SyntaxName(Syntax syntax);
16661677

1678+
public:
1679+
16671680
// Find a top-level message type by name (not full_name). Returns nullptr if
16681681
// not found.
16691682
const Descriptor* FindMessageTypeByName(absl::string_view name) const;

0 commit comments

Comments
 (0)