Skip to content
Snippets Groups Projects
Commit 33a21684 authored by temiola's avatar temiola Committed by Nicolas Noble
Browse files

Fixes package prefixes

Fixes how module names for messages with package prefixes are rendered.

- detected while prototyping with beefcake
- fixed on the internal beefcake fork here
[]

This change replicates that fix for the official code generator.

TODO: add a test; what's normal done to test features like this the proto
codebase? Add another test.proto/golden file?
	Change on 2014/12/11 by temiola <temiola@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81916292
parent 94204dda
No related branches found
No related tags found
No related merge requests found
......@@ -98,8 +98,8 @@ bool HasBidiStreaming(const google::protobuf::FileDescriptor* file) {
string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) {
string temp =
"#include \"net/grpc/cpp/internal/client/internal_stub.h\"\n"
"#include \"net/grpc/cpp/public/status.h\"\n"
"#include \"src/cpp/client/internal_stub.h\"\n"
"#include \"grpc++/status.h\"\n"
"\n"
"namespace grpc {\n"
"class ChannelInterface;\n"
......@@ -125,10 +125,10 @@ string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) {
}
string GetSourceIncludes() {
return "#include \"net/grpc/cpp/internal/rpc_method.h\"\n"
"#include \"net/grpc/cpp/internal/server/rpc_service_method.h\"\n"
"#include \"net/grpc/cpp/public/channel_interface.h\"\n"
"#include \"net/grpc/cpp/public/stream.h\"\n";
return "#include \"src/cpp/rpc_method.h\"\n"
"#include \"src/cpp/server/rpc_service_method.h\"\n"
"#include \"grpc++/channel_interface.h\"\n"
"#include \"grpc++/stream.h\"\n";
}
void PrintHeaderClientMethod(google::protobuf::io::Printer* printer,
......
......@@ -93,14 +93,6 @@ inline bool ReplacePrefix(string* s, const string& from, const string& to) {
return true;
}
// RubyTypeOf updates a proto type to the required ruby equivalent.
inline string RubyTypeOf(const string& a_type, const string& package) {
string res(a_type);
ReplacePrefix(&res, package, ""); // remove the leading package if present
ReplacePrefix(&res, ".", ""); // remove the leading . (no package)
return ReplaceAll(res, ".", "::"); // switch '.' to the ruby module delimiter
}
// CapitalizeString capitalizes a string.
inline string CapitalizeString(string s) {
if (!s.empty()) {
......@@ -111,6 +103,29 @@ inline string CapitalizeString(string s) {
return s;
}
// RubyTypeOf updates a proto type to the required ruby equivalent.
inline string RubyTypeOf(const string& a_type, const string& package) {
string res(a_type);
ReplacePrefix(&res, package, ""); // remove the leading package if present
ReplacePrefix(&res, ".", ""); // remove the leading . (no package)
if (res.find('.') == string::npos) {
return res;
} else {
vector<string> prefixes_and_type = Split(res, '.');
for (int i = 0; i < prefixes_and_type.size(); ++i) {
if (i != 0) {
res += "::"; // switch '.' to the ruby module delim
}
if (i < prefixes_and_type.size() - 1) {
res += CapitalizeString(prefixes_and_type[i]); // capitalize pkgs
} else {
res += prefixes_and_type[i];
}
}
return res;
}
}
} // namespace grpc_ruby_generator
#endif // NET_GRPC_COMPILER_RUBY_GENERATOR_STRING_INL_H_
......@@ -95,8 +95,8 @@ void DoEmpty(std::shared_ptr<ChannelInterface> channel) {
gpr_log(GPR_INFO, "Sending an empty rpc...");
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel));
google::protobuf::Empty request = google::protobuf::Empty::default_instance();
google::protobuf::Empty response = google::protobuf::Empty::default_instance();
grpc::testing::Empty request = grpc::testing::Empty::default_instance();
grpc::testing::Empty response = grpc::testing::Empty::default_instance();
ClientContext context;
grpc::Status s = stub->EmptyCall(&context, request, &response);
......
......@@ -2,8 +2,8 @@
// of unary/streaming requests/responses.
syntax = "proto2";
import "net/grpc/cpp/test/interop/empty.proto";
import "net/grpc/cpp/test/interop/messages.proto";
import "test/cpp/interop/empty.proto";
import "test/cpp/interop/messages.proto";
package grpc.testing;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment