/* * * Copyright 2016 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include "src/compiler/node_generator.h" #include <map> #include "src/compiler/config.h" #include "src/compiler/generator_helpers.h" #include "src/compiler/node_generator_helpers.h" Descriptor; FileDescriptor; MethodDescriptor; ServiceDescriptor; Printer; StringOutputStream; map; namespace grpc_node_generator { namespace { // Returns the alias we assign to the module of the given .proto filename // when importing. Copied entirely from // github:google/protobuf/src/google/protobuf/compiler/js/js_generator.cc#L154 std::string ModuleAlias(const std::string filename) { … } // Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript // message file foo/bar/baz.js std::string GetJSMessageFilename(const std::string& filename) { … } // Given a filename like foo/bar/baz.proto, returns the root directory // path ../../ std::string GetRootPath(const std::string& from_filename, const std::string& to_filename) { … } // Return the relative path to load to_file from the directory containing // from_file, assuming that both paths are relative to the same directory std::string GetRelativePath(const std::string& from_file, const std::string& to_file) { … } /* Finds all message types used in all services in the file, and returns them * as a map of fully qualified message type name to message descriptor */ map<std::string, const Descriptor*> GetAllMessages(const FileDescriptor* file) { … } std::string MessageIdentifierName(const std::string& name) { … } std::string NodeObjectPath(const Descriptor* descriptor) { … } // Prints out the message serializer and deserializer functions void PrintMessageTransformer(const Descriptor* descriptor, Printer* out, const Parameters& params) { … } void PrintMethod(const MethodDescriptor* method, Printer* out) { … } // Prints out the service descriptor object void PrintService(const ServiceDescriptor* service, Printer* out) { … } void PrintImports(const FileDescriptor* file, Printer* out) { … } void PrintTransformers(const FileDescriptor* file, Printer* out, const Parameters& params) { … } void PrintServices(const FileDescriptor* file, Printer* out) { … } } // namespace std::string GenerateFile(const FileDescriptor* file, const Parameters& params) { … } } // namespace grpc_node_generator