node_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 Node gRPC service interface out of Protobuf IDL.
20 
21 #include <memory>
22 
23 #include "src/compiler/config.h"
26 
29 
31  public:
34 
35  uint64_t GetSupportedFeatures() const override {
36  return FEATURE_PROTO3_OPTIONAL;
37  }
38 
40  const std::string& parameter,
42  std::string* error) const override {
43  grpc_node_generator::Parameters generator_parameters;
44  generator_parameters.minimum_node_version = 4;
45 
46  if (!parameter.empty()) {
47  std::vector<std::string> parameters_list =
48  grpc_generator::tokenize(parameter, ",");
49  for (auto parameter_string = parameters_list.begin();
50  parameter_string != parameters_list.end(); parameter_string++) {
51  std::vector<std::string> param =
52  grpc_generator::tokenize(*parameter_string, "=");
53  if (param[0] == "minimum_node_version") {
54  sscanf(param[1].c_str(), "%d",
55  &generator_parameters.minimum_node_version);
56  } else {
57  *error = std::string("Unknown parameter: ") + *parameter_string;
58  return false;
59  }
60  }
61  }
62 
63  std::string code = GenerateFile(file, generator_parameters);
64  if (code.size() == 0) {
65  return true;
66  }
67 
68  // Get output file name
69  std::string file_name = GetJSServiceFilename(file->name());
70 
71  std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
72  context->Open(file_name));
74  coded_out.WriteRaw(code.data(), code.size());
75  return true;
76  }
77 };
78 
79 int main(int argc, char* argv[]) {
80  NodeGrpcGenerator generator;
81  return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
82 }
grpc_node_generator::GenerateFile
std::string GenerateFile(const FileDescriptor *file, const Parameters &params)
Definition: node_generator.cc:246
grpc::protobuf::FileDescriptor
GRPC_CUSTOM_FILEDESCRIPTOR FileDescriptor
Definition: include/grpcpp/impl/codegen/config_protobuf.h:85
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_node_generator::Parameters
Definition: node_generator.h:27
grpc_generator::tokenize
std::vector< std::string > tokenize(const std::string &input, const std::string &delimiters)
Definition: generator_helpers.h:82
main
int main(int argc, char *argv[])
Definition: node_plugin.cc:79
grpc::protobuf::compiler::GeneratorContext
GRPC_CUSTOM_GENERATORCONTEXT GeneratorContext
Definition: src/compiler/config.h:42
grpc::protobuf::compiler::CodeGenerator
GRPC_CUSTOM_CODEGENERATOR CodeGenerator
Definition: src/compiler/config.h:41
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
NodeGrpcGenerator::~NodeGrpcGenerator
~NodeGrpcGenerator()
Definition: node_plugin.cc:33
grpc::protobuf::io::CodedOutputStream
GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream
Definition: src/compiler/config.h:55
node_generator_helpers.h
node_generator.h
NodeGrpcGenerator::Generate
bool Generate(const grpc::protobuf::FileDescriptor *file, const std::string &parameter, grpc::protobuf::compiler::GeneratorContext *context, std::string *error) const override
Definition: node_plugin.cc:39
grpc::protobuf::compiler::PluginMain
static int PluginMain(int argc, char *argv[], const CodeGenerator *generator)
Definition: src/compiler/config.h:43
grpc_node_generator::Parameters::minimum_node_version
int minimum_node_version
Definition: node_generator.h:29
NodeGrpcGenerator
Definition: node_plugin.cc:30
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
NodeGrpcGenerator::GetSupportedFeatures
uint64_t GetSupportedFeatures() const override
Definition: node_plugin.cc:35
NodeGrpcGenerator::NodeGrpcGenerator
NodeGrpcGenerator()
Definition: node_plugin.cc:32
code
Definition: bloaty/third_party/zlib/contrib/infback9/inftree9.h:24
file::name
char * name
Definition: bloaty/third_party/zlib/examples/gzappend.c:176
grpc_node_generator::GetJSServiceFilename
std::string GetJSServiceFilename(const std::string &filename)
Definition: node_generator_helpers.h:29


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:43