csharp_plugin.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 // Generates C# gRPC service interface out of Protobuf IDL.
20 
21 #include <memory>
22 
23 #include "src/compiler/config.h"
26 
28  public:
31 
32  uint64_t GetSupportedFeatures() const override {
33  return FEATURE_PROTO3_OPTIONAL;
34  }
35 
37  const std::string& parameter,
39  std::string* error) const override {
40  std::vector<std::pair<std::string, std::string> > options;
42 
43  bool generate_client = true;
44  bool generate_server = true;
45  bool internal_access = false;
46  // the suffix that will get appended to the name generated from the name
47  // of the original .proto file
48  std::string file_suffix = "Grpc.cs";
49  for (size_t i = 0; i < options.size(); i++) {
50  if (options[i].first == "no_client") {
51  generate_client = false;
52  } else if (options[i].first == "no_server") {
53  generate_server = false;
54  } else if (options[i].first == "internal_access") {
55  internal_access = true;
56  } else if (options[i].first == "file_suffix") {
57  file_suffix = options[i].second;
58  } else {
59  *error = "Unknown generator option: " + options[i].first;
60  return false;
61  }
62  }
63 
65  file, generate_client, generate_server, internal_access);
66  if (code.size() == 0) {
67  return true; // don't generate a file if there are no services
68  }
69 
70  // Get output file name.
71  std::string file_name;
73  file_name)) {
74  return false;
75  }
76  std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
77  context->Open(file_name));
79  coded_out.WriteRaw(code.data(), code.size());
80  return true;
81  }
82 };
83 
84 int main(int argc, char* argv[]) {
85  CSharpGrpcGenerator generator;
86  return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
87 }
CSharpGrpcGenerator::GetSupportedFeatures
uint64_t GetSupportedFeatures() const override
Definition: csharp_plugin.cc:32
grpc::protobuf::FileDescriptor
GRPC_CUSTOM_FILEDESCRIPTOR FileDescriptor
Definition: include/grpcpp/impl/codegen/config_protobuf.h:85
csharp_generator.h
options
double_dict options[]
Definition: capstone_test.c:55
config.h
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
grpc::protobuf::compiler::GeneratorContext
GRPC_CUSTOM_GENERATORCONTEXT GeneratorContext
Definition: src/compiler/config.h:42
grpc::protobuf::compiler::ParseGeneratorParameter
static void ParseGeneratorParameter(const string &parameter, std::vector< std::pair< string, string > > *options)
Definition: src/compiler/config.h:47
csharp_generator_helpers.h
grpc::protobuf::compiler::CodeGenerator
GRPC_CUSTOM_CODEGENERATOR CodeGenerator
Definition: src/compiler/config.h:41
CSharpGrpcGenerator::CSharpGrpcGenerator
CSharpGrpcGenerator()
Definition: csharp_plugin.cc:29
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
CSharpGrpcGenerator
Definition: csharp_plugin.cc:27
grpc_csharp_generator::GetServices
std::string GetServices(const FileDescriptor *file, bool generate_client, bool generate_server, bool internal_access)
Definition: src/compiler/csharp_generator.cc:775
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
grpc::protobuf::io::CodedOutputStream
GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream
Definition: src/compiler/config.h:55
main
int main(int argc, char *argv[])
Definition: csharp_plugin.cc:84
grpc::protobuf::compiler::PluginMain
static int PluginMain(int argc, char *argv[], const CodeGenerator *generator)
Definition: src/compiler/config.h:43
grpc_csharp_generator::ServicesFilename
bool ServicesFilename(const grpc::protobuf::FileDescriptor *file, const std::string &file_suffix, std::string &out_file_name_or_error)
Definition: csharp_generator_helpers.h:27
first
StrT first
Definition: cxa_demangle.cpp:4884
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
code
Definition: bloaty/third_party/zlib/contrib/infback9/inftree9.h:24
CSharpGrpcGenerator::~CSharpGrpcGenerator
~CSharpGrpcGenerator()
Definition: csharp_plugin.cc:30
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
CSharpGrpcGenerator::Generate
bool Generate(const grpc::protobuf::FileDescriptor *file, const std::string &parameter, grpc::protobuf::compiler::GeneratorContext *context, std::string *error) const override
Definition: csharp_plugin.cc:36


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:01