From 58e60dbf4c38069cb3ed1151fb45bd514fbc53fa Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 14 Jul 2023 21:56:33 +0000 Subject: [PATCH] Add support in protoc-gen-cppstream for optional fields in proto3 This support is optional. experimental_allow_proto3_optional must be included in the --cppstream_opt field to enable this. Test: m -j frameworks/base/tools/streaming_proto Fixes: 291329285 Change-Id: I7b985b84edf0cda46d06a9ebc39df574695ef418 --- tools/streaming_proto/OWNERS | 1 + tools/streaming_proto/cpp/main.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 tools/streaming_proto/OWNERS diff --git a/tools/streaming_proto/OWNERS b/tools/streaming_proto/OWNERS new file mode 100644 index 0000000000000..5f6e59f82c8ac --- /dev/null +++ b/tools/streaming_proto/OWNERS @@ -0,0 +1 @@ +mwachens@google.com diff --git a/tools/streaming_proto/cpp/main.cpp b/tools/streaming_proto/cpp/main.cpp index fe9a438d81d7a..905ed354049b2 100644 --- a/tools/streaming_proto/cpp/main.cpp +++ b/tools/streaming_proto/cpp/main.cpp @@ -119,9 +119,8 @@ write_message(stringstream& text, const DescriptorProto& message, const string& text << endl; } -static void -write_header_file(CodeGeneratorResponse* response, const FileDescriptorProto& file_descriptor) -{ +static void write_header_file(const string& request_parameter, CodeGeneratorResponse* response, + const FileDescriptorProto& file_descriptor) { stringstream text; text << "// Generated by protoc-gen-cppstream. DO NOT MODIFY." << endl; @@ -159,6 +158,9 @@ write_header_file(CodeGeneratorResponse* response, const FileDescriptorProto& fi text << endl; text << "#endif // " << header << endl; + if (request_parameter.find("experimental_allow_proto3_optional") != string::npos) { + response->set_supported_features(CodeGeneratorResponse::FEATURE_PROTO3_OPTIONAL); + } CodeGeneratorResponse::File* file_response = response->add_file(); file_response->set_name(make_filename(file_descriptor)); file_response->set_content(text.str()); @@ -182,7 +184,7 @@ int main(int argc, char const *argv[]) for (int i=0; i