Skip to content

Commit

Permalink
moved GetMethodType function to generator_helpers.h
Browse files Browse the repository at this point in the history
  • Loading branch information
jtattermusch committed May 7, 2015
1 parent efa702b commit b5897bf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/compiler/csharp_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <vector>

#include "src/compiler/config.h"
#include "src/compiler/csharp_generator_helpers.h"
#include "src/compiler/csharp_generator.h"

using grpc::protobuf::FileDescriptor;
Expand All @@ -44,35 +45,18 @@ using grpc::protobuf::ServiceDescriptor;
using grpc::protobuf::MethodDescriptor;
using grpc::protobuf::io::Printer;
using grpc::protobuf::io::StringOutputStream;
using grpc_generator::MethodType;
using grpc_generator::GetMethodType;
using grpc_generator::METHODTYPE_NO_STREAMING;
using grpc_generator::METHODTYPE_CLIENT_STREAMING;
using grpc_generator::METHODTYPE_SERVER_STREAMING;
using grpc_generator::METHODTYPE_BIDI_STREAMING;
using std::map;
using std::vector;

namespace grpc_csharp_generator {
namespace {

enum MethodType {
METHODTYPE_NO_STREAMING,
METHODTYPE_CLIENT_STREAMING,
METHODTYPE_SERVER_STREAMING,
METHODTYPE_BIDI_STREAMING
};

MethodType GetMethodType(const MethodDescriptor *method) {
if (method->client_streaming()) {
if (method->server_streaming()) {
return METHODTYPE_BIDI_STREAMING;
} else {
return METHODTYPE_CLIENT_STREAMING;
}
} else {
if (method->server_streaming()) {
return METHODTYPE_SERVER_STREAMING;
} else {
return METHODTYPE_NO_STREAMING;
}
}
}

std::string GetCSharpNamespace(const FileDescriptor* file) {
// TODO(jtattermusch): this should be based on csharp_namespace option
return file->package();
Expand Down
23 changes: 23 additions & 0 deletions src/compiler/generator_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@ inline grpc::string FileNameInUpperCamel(const grpc::protobuf::FileDescriptor *f
return LowerUnderscoreToUpperCamel(StripProto(file->name()));
}

enum MethodType {
METHODTYPE_NO_STREAMING,
METHODTYPE_CLIENT_STREAMING,
METHODTYPE_SERVER_STREAMING,
METHODTYPE_BIDI_STREAMING
};

inline MethodType GetMethodType(const grpc::protobuf::MethodDescriptor *method) {
if (method->client_streaming()) {
if (method->server_streaming()) {
return METHODTYPE_BIDI_STREAMING;
} else {
return METHODTYPE_CLIENT_STREAMING;
}
} else {
if (method->server_streaming()) {
return METHODTYPE_SERVER_STREAMING;
} else {
return METHODTYPE_NO_STREAMING;
}
}
}

} // namespace grpc_generator

#endif // GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H

0 comments on commit b5897bf

Please sign in to comment.