Replaced grpc::string with std::string

pull/23350/head
Esun Kim 4 years ago
parent adcc46abeb
commit 165ee5007a
  1. 2
      doc/unit_testing.md
  2. 2
      examples/cpp/helloworld/cocoapods/HelloWorldCpp/ViewController.mm
  3. 2
      examples/cpp/metadata/greeter_client.cc
  4. 12
      include/grpcpp/channel_impl.h
  5. 8
      include/grpcpp/create_channel.h
  6. 6
      include/grpcpp/create_channel_impl.h
  7. 6
      include/grpcpp/create_channel_posix.h
  8. 70
      include/grpcpp/create_channel_posix_impl.h
  9. 4
      include/grpcpp/ext/proto_server_reflection_plugin_impl.h
  10. 2
      include/grpcpp/ext/server_load_reporting.h
  11. 2
      include/grpcpp/ext/server_load_reporting_impl.h
  12. 26
      include/grpcpp/generic/generic_stub_impl.h
  13. 2
      include/grpcpp/grpcpp.h
  14. 2
      include/grpcpp/health_check_service_interface.h
  15. 4
      include/grpcpp/impl/channel_argument_option.h
  16. 16
      include/grpcpp/impl/codegen/async_generic_service.h
  17. 22
      include/grpcpp/impl/codegen/call_op_set.h
  18. 19
      include/grpcpp/impl/codegen/client_context_impl.h
  19. 15
      include/grpcpp/impl/codegen/config.h
  20. 5
      include/grpcpp/impl/codegen/interceptor.h
  21. 26
      include/grpcpp/impl/codegen/interceptor_common.h
  22. 12
      include/grpcpp/impl/codegen/metadata_map.h
  23. 7
      include/grpcpp/impl/codegen/security/auth_context.h
  24. 12
      include/grpcpp/impl/codegen/server_context_impl.h
  25. 4
      include/grpcpp/impl/codegen/server_interface.h
  26. 12
      include/grpcpp/impl/codegen/slice.h
  27. 14
      include/grpcpp/impl/codegen/status.h
  28. 4
      include/grpcpp/impl/codegen/string_ref.h
  29. 4
      include/grpcpp/impl/server_builder_plugin.h
  30. 2
      include/grpcpp/impl/server_initializer_impl.h
  31. 2
      include/grpcpp/resource_quota.h
  32. 2
      include/grpcpp/resource_quota_impl.h
  33. 16
      include/grpcpp/security/alts_context.h
  34. 2
      include/grpcpp/security/auth_metadata_processor_impl.h
  35. 12
      include/grpcpp/security/credentials.h
  36. 58
      include/grpcpp/security/credentials_impl.h
  37. 6
      include/grpcpp/security/server_credentials.h
  38. 3
      include/grpcpp/security/server_credentials_impl.h
  39. 36
      include/grpcpp/security/tls_credentials_options.h
  40. 14
      include/grpcpp/server_builder.h
  41. 417
      include/grpcpp/server_builder_impl.h
  42. 8
      include/grpcpp/server_impl.h
  43. 20
      include/grpcpp/support/channel_arguments_impl.h
  44. 2
      include/grpcpp/support/validate_service_config.h
  45. 10
      include/grpcpp/test/server_context_test_spouse.h
  46. 11
      src/compiler/config.h
  47. 233
      src/compiler/cpp_generator.cc
  48. 86
      src/compiler/cpp_generator.h
  49. 14
      src/compiler/cpp_generator_helpers.h
  50. 28
      src/compiler/cpp_plugin.h
  51. 24
      src/compiler/csharp_generator.cc
  52. 6
      src/compiler/csharp_generator.h
  53. 5
      src/compiler/csharp_generator_helpers.h
  54. 10
      src/compiler/csharp_plugin.cc
  55. 75
      src/compiler/generator_helpers.h
  56. 57
      src/compiler/node_generator.cc
  57. 4
      src/compiler/node_generator.h
  58. 4
      src/compiler/node_generator_helpers.h
  59. 14
      src/compiler/node_plugin.cc
  60. 70
      src/compiler/objective_c_generator.cc
  61. 2
      src/compiler/objective_c_generator.h
  62. 56
      src/compiler/objective_c_generator_helpers.h
  63. 74
      src/compiler/objective_c_plugin.cc
  64. 34
      src/compiler/php_generator.cc
  65. 6
      src/compiler/php_generator.h
  66. 20
      src/compiler/php_generator_helpers.h
  67. 12
      src/compiler/php_plugin.cc
  68. 66
      src/compiler/protobuf_plugin.h
  69. 132
      src/compiler/python_generator.cc
  70. 12
      src/compiler/python_generator.h
  71. 40
      src/compiler/python_generator_helpers.h
  72. 18
      src/compiler/python_private_generator.h
  73. 34
      src/compiler/ruby_generator.cc
  74. 2
      src/compiler/ruby_generator.h
  75. 6
      src/compiler/ruby_generator_helpers-inl.h
  76. 10
      src/compiler/ruby_generator_map-inl.h
  77. 48
      src/compiler/ruby_generator_string-inl.h
  78. 8
      src/compiler/ruby_plugin.cc
  79. 58
      src/compiler/schema_interface.h
  80. 16
      src/cpp/client/channel_cc.cc
  81. 8
      src/cpp/client/client_context.cc
  82. 6
      src/cpp/client/create_channel.cc
  83. 2
      src/cpp/client/create_channel_internal.cc
  84. 2
      src/cpp/client/create_channel_internal.h
  85. 6
      src/cpp/client/create_channel_posix.cc
  86. 4
      src/cpp/client/insecure_credentials.cc
  87. 18
      src/cpp/client/secure_credentials.cc
  88. 8
      src/cpp/client/secure_credentials.h
  89. 16
      src/cpp/common/alts_context.cc
  90. 22
      src/cpp/common/channel_arguments.cc
  91. 2
      src/cpp/common/resource_quota_cc.cc
  92. 8
      src/cpp/common/secure_auth_context.cc
  93. 8
      src/cpp/common/secure_auth_context.h
  94. 6
      src/cpp/common/secure_channel_arguments.cc
  95. 34
      src/cpp/common/tls_credentials_options.cc
  96. 5
      src/cpp/common/validate_service_config.cc
  97. 2
      src/cpp/common/version_cc.cc
  98. 18
      src/cpp/ext/proto_server_reflection.cc
  99. 10
      src/cpp/ext/proto_server_reflection.h
  100. 4
      src/cpp/ext/proto_server_reflection_plugin.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -102,7 +102,7 @@ class FakeClient {
EchoRequest request;
EchoResponse response;
ClientContext context;
grpc::string msg("hello");
std::string msg("hello");
std::unique_ptr<ClientReaderWriterInterface<EchoRequest, EchoResponse>>
stream = stub_->BidiStream(&context);

@ -44,7 +44,7 @@ const uint8_t kMessage[] =
CreateChannel("localhost:50051", grpc::InsecureChannelCredentials());
generic_stub_.reset(new grpc::GenericStub(channel));
const grpc::string kMethodName("/helloworld.Greeter/SayHello");
const std::string kMethodName("/helloworld.Greeter/SayHello");
void* got_tag;
bool ok;

@ -60,7 +60,7 @@ class CustomHeaderClient {
// Setting custom binary metadata
char bytes[8] = {'\0', '\1', '\2', '\3',
'\4', '\5', '\6', '\7'};
context.AddMetadata("custom-bin", grpc::string(bytes, 8));
context.AddMetadata("custom-bin", std::string(bytes, 8));
// The actual RPC.
Status status = stub_->SayHello(&context, request, &reply);

@ -38,7 +38,7 @@ class ChannelTestPeer;
} // namespace testing
std::shared_ptr<::grpc_impl::Channel> CreateChannelInternal(
const grpc::string& host, grpc_channel* c_channel,
const std::string& host, grpc_channel* c_channel,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
@ -65,11 +65,11 @@ class Channel final : public ::grpc::ChannelInterface,
grpc_connectivity_state GetState(bool try_to_connect) override;
/// Returns the LB policy name, or the empty string if not yet available.
grpc::string GetLoadBalancingPolicyName() const;
std::string GetLoadBalancingPolicyName() const;
/// Returns the service config in JSON form, or the empty string if
/// not available.
grpc::string GetServiceConfigJSON() const;
std::string GetServiceConfigJSON() const;
private:
template <class InputMessage, class OutputMessage>
@ -77,12 +77,12 @@ class Channel final : public ::grpc::ChannelInterface,
friend class ::grpc::testing::ChannelTestPeer;
friend void experimental::ChannelResetConnectionBackoff(Channel* channel);
friend std::shared_ptr<Channel> grpc::CreateChannelInternal(
const grpc::string& host, grpc_channel* c_channel,
const std::string& host, grpc_channel* c_channel,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
friend class ::grpc::internal::InterceptedChannel;
Channel(const grpc::string& host, grpc_channel* c_channel,
Channel(const std::string& host, grpc_channel* c_channel,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
@ -108,7 +108,7 @@ class Channel final : public ::grpc::ChannelInterface,
::grpc_impl::ClientContext* context, ::grpc_impl::CompletionQueue* cq,
size_t interceptor_pos) override;
const grpc::string host_;
const std::string host_;
grpc_channel* const c_channel_; // owned
// mu_ protects callback_cq_ (the per-channel callbackable completion queue)

@ -25,14 +25,13 @@
namespace grpc {
static inline std::shared_ptr<::grpc::Channel> CreateChannel(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<ChannelCredentials>& creds) {
return ::grpc_impl::CreateChannelImpl(target, creds);
}
static inline std::shared_ptr<::grpc::Channel> CreateCustomChannel(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const std::string& target, const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args) {
return ::grpc_impl::CreateCustomChannelImpl(target, creds, args);
}
@ -41,8 +40,7 @@ namespace experimental {
static inline std::shared_ptr<::grpc::Channel>
CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const std::string& target, const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args,
std::vector<
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>

@ -35,7 +35,7 @@ namespace grpc_impl {
/// hold an object or is invalid, a lame channel (one on which all operations
/// fail) is returned.
std::shared_ptr<::grpc::Channel> CreateChannelImpl(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<::grpc::ChannelCredentials>& creds);
/// Create a new \em custom \a Channel pointing to \a target.
@ -49,7 +49,7 @@ std::shared_ptr<::grpc::Channel> CreateChannelImpl(
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<::grpc::Channel> CreateCustomChannelImpl(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<::grpc::ChannelCredentials>& creds,
const ::grpc::ChannelArguments& args);
@ -66,7 +66,7 @@ namespace experimental {
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<::grpc::Channel> CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const ::grpc::ChannelArguments& args,
std::vector<

@ -34,7 +34,7 @@ namespace grpc {
/// \param target The name of the target.
/// \param fd The file descriptor representing a socket.
std::shared_ptr<grpc::Channel> CreateInsecureChannelFromFd(
const grpc::string& target, int fd);
const std::string& target, int fd);
/// Create a new \a Channel communicating over given file descriptor with custom
/// channel arguments.
@ -43,7 +43,7 @@ std::shared_ptr<grpc::Channel> CreateInsecureChannelFromFd(
/// \param fd The file descriptor representing a socket.
/// \param args Options for channel creation.
std::shared_ptr<grpc::Channel> CreateCustomInsecureChannelFromFd(
const grpc::string& target, int fd, const grpc::ChannelArguments& args);
const std::string& target, int fd, const grpc::ChannelArguments& args);
namespace experimental {
@ -56,7 +56,7 @@ namespace experimental {
/// \param interceptor_creators Vector of interceptor factory objects.
std::shared_ptr<grpc::Channel>
CreateCustomInsecureChannelWithInterceptorsFromFd(
const grpc::string& target, int fd, const grpc::ChannelArguments& args,
const std::string& target, int fd, const grpc::ChannelArguments& args,
std::unique_ptr<std::vector<
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>>
interceptor_creators);

@ -0,0 +1,70 @@
/*
*
* 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.
*
*/
#ifndef GRPCPP_CREATE_CHANNEL_POSIX_IMPL_H
#define GRPCPP_CREATE_CHANNEL_POSIX_IMPL_H
#include <memory>
#include <grpc/support/port_platform.h>
#include <grpcpp/channel.h>
#include <grpcpp/support/channel_arguments.h>
namespace grpc_impl {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD
/// Create a new \a Channel communicating over the given file descriptor.
///
/// \param target The name of the target.
/// \param fd The file descriptor representing a socket.
std::shared_ptr<grpc::Channel> CreateInsecureChannelFromFd(
const std::string& target, int fd);
/// Create a new \a Channel communicating over given file descriptor with custom
/// channel arguments.
///
/// \param target The name of the target.
/// \param fd The file descriptor representing a socket.
/// \param args Options for channel creation.
std::shared_ptr<grpc::Channel> CreateCustomInsecureChannelFromFd(
const std::string& target, int fd, const grpc::ChannelArguments& args);
namespace experimental {
/// Create a new \a Channel communicating over given file descriptor with custom
/// channel arguments.
///
/// \param target The name of the target.
/// \param fd The file descriptor representing a socket.
/// \param args Options for channel creation.
/// \param interceptor_creators Vector of interceptor factory objects.
std::shared_ptr<grpc::Channel>
CreateCustomInsecureChannelWithInterceptorsFromFd(
const std::string& target, int fd, const grpc::ChannelArguments& args,
std::unique_ptr<std::vector<
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>>
interceptor_creators);
} // namespace experimental
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
} // namespace grpc_impl
#endif // GRPCPP_CREATE_CHANNEL_POSIX_IMPL_H

@ -34,10 +34,10 @@ namespace reflection {
class ProtoServerReflectionPlugin : public ::grpc::ServerBuilderPlugin {
public:
ProtoServerReflectionPlugin();
::grpc::string name() override;
::std::string name() override;
void InitServer(::grpc_impl::ServerInitializer* si) override;
void Finish(::grpc_impl::ServerInitializer* si) override;
void ChangeArguments(const ::grpc::string& name, void* value) override;
void ChangeArguments(const ::std::string& name, void* value) override;
bool has_async_methods() const override;
bool has_sync_methods() const override;

@ -30,7 +30,7 @@ typedef ::grpc_impl::load_reporter::experimental::
LoadReportingServiceServerBuilderOption;
static inline void AddLoadReportingCost(grpc::ServerContext* ctx,
const grpc::string& cost_name,
const std::string& cost_name,
double cost_value) {
::grpc_impl::load_reporter::experimental::AddLoadReportingCost(ctx, cost_name,
cost_value);

@ -45,7 +45,7 @@ class LoadReportingServiceServerBuilderOption
// Adds the load reporting cost with \a cost_name and \a cost_value in the
// trailing metadata of the server context.
void AddLoadReportingCost(grpc::ServerContext* ctx,
const grpc::string& cost_name, double cost_value);
const std::string& cost_name, double cost_value);
} // namespace experimental
} // namespace load_reporter

@ -53,7 +53,7 @@ class TemplatedGenericStub final {
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
PrepareCall(ClientContext* context, const grpc::string& method,
PrepareCall(ClientContext* context, const std::string& method,
CompletionQueue* cq) {
return CallInternal(channel_.get(), context, method, cq, false, nullptr);
}
@ -63,7 +63,7 @@ class TemplatedGenericStub final {
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<ClientAsyncResponseReader<ResponseType>> PrepareUnaryCall(
ClientContext* context, const grpc::string& method,
ClientContext* context, const std::string& method,
const RequestType& request, CompletionQueue* cq) {
return std::unique_ptr<ClientAsyncResponseReader<ResponseType>>(
internal::ClientAsyncResponseReaderFactory<ResponseType>::Create(
@ -80,7 +80,7 @@ class TemplatedGenericStub final {
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>> Call(
ClientContext* context, const grpc::string& method, CompletionQueue* cq,
ClientContext* context, const std::string& method, CompletionQueue* cq,
void* tag) {
return CallInternal(channel_.get(), context, method, cq, true, tag);
}
@ -88,7 +88,7 @@ class TemplatedGenericStub final {
#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(ClientContext* context, const grpc::string& method,
void UnaryCall(ClientContext* context, const std::string& method,
const RequestType* request, ResponseType* response,
std::function<void(grpc::Status)> on_completion) {
UnaryCallInternal(context, method, request, response,
@ -99,7 +99,7 @@ class TemplatedGenericStub final {
/// \a context and specifying the \a request and \a response buffers.
/// Like any other reactor-based RPC, it will not be activated until
/// StartCall is invoked on its reactor.
void PrepareUnaryCall(ClientContext* context, const grpc::string& method,
void PrepareUnaryCall(ClientContext* context, const std::string& method,
const RequestType* request, ResponseType* response,
ClientUnaryReactor* reactor) {
PrepareUnaryCallInternal(context, method, request, response, reactor);
@ -109,7 +109,7 @@ class TemplatedGenericStub final {
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
ClientContext* context, const grpc::string& method,
ClientContext* context, const std::string& method,
ClientBidiReactor<RequestType, ResponseType>* reactor) {
PrepareBidiStreamingCallInternal(context, method, reactor);
}
@ -124,7 +124,7 @@ class TemplatedGenericStub final {
/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(ClientContext* context, const grpc::string& method,
void UnaryCall(ClientContext* context, const std::string& method,
const RequestType* request, ResponseType* response,
std::function<void(grpc::Status)> on_completion) {
stub_->UnaryCallInternal(context, method, request, response,
@ -135,7 +135,7 @@ class TemplatedGenericStub final {
/// \a context and specifying the \a request and \a response buffers.
/// Like any other reactor-based RPC, it will not be activated until
/// StartCall is invoked on its reactor.
void PrepareUnaryCall(ClientContext* context, const grpc::string& method,
void PrepareUnaryCall(ClientContext* context, const std::string& method,
const RequestType* request, ResponseType* response,
ClientUnaryReactor* reactor) {
stub_->PrepareUnaryCallInternal(context, method, request, response,
@ -146,7 +146,7 @@ class TemplatedGenericStub final {
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
ClientContext* context, const grpc::string& method,
ClientContext* context, const std::string& method,
ClientBidiReactor<RequestType, ResponseType>* reactor) {
stub_->PrepareBidiStreamingCallInternal(context, method, reactor);
}
@ -163,7 +163,7 @@ class TemplatedGenericStub final {
private:
std::shared_ptr<grpc::ChannelInterface> channel_;
void UnaryCallInternal(ClientContext* context, const grpc::string& method,
void UnaryCallInternal(ClientContext* context, const std::string& method,
const RequestType* request, ResponseType* response,
std::function<void(grpc::Status)> on_completion) {
internal::CallbackUnaryCall(
@ -174,7 +174,7 @@ class TemplatedGenericStub final {
}
void PrepareUnaryCallInternal(ClientContext* context,
const grpc::string& method,
const std::string& method,
const RequestType* request,
ResponseType* response,
ClientUnaryReactor* reactor) {
@ -186,7 +186,7 @@ class TemplatedGenericStub final {
}
void PrepareBidiStreamingCallInternal(
ClientContext* context, const grpc::string& method,
ClientContext* context, const std::string& method,
ClientBidiReactor<RequestType, ResponseType>* reactor) {
internal::ClientCallbackReaderWriterFactory<RequestType, ResponseType>::
Create(channel_.get(),
@ -197,7 +197,7 @@ class TemplatedGenericStub final {
std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
CallInternal(grpc::ChannelInterface* channel, ClientContext* context,
const grpc::string& method, CompletionQueue* cq, bool start,
const std::string& method, CompletionQueue* cq, bool start,
void* tag) {
return std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>(
internal::ClientAsyncReaderWriterFactory<RequestType, ResponseType>::

@ -63,7 +63,7 @@
namespace grpc {
/// Return gRPC library version.
grpc::string Version();
std::string Version();
} // namespace grpc
#endif // GRPCPP_GRPCPP_H

@ -33,7 +33,7 @@ class HealthCheckServiceInterface {
virtual ~HealthCheckServiceInterface() {}
/// Set or change the serving status of the given \a service_name.
virtual void SetServingStatus(const grpc::string& service_name,
virtual void SetServingStatus(const std::string& service_name,
bool serving) = 0;
/// Apply to all registered service names.
virtual void SetServingStatus(bool serving) = 0;

@ -28,9 +28,9 @@
namespace grpc {
std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
const grpc::string& name, const grpc::string& value);
const std::string& name, const std::string& value);
std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(
const grpc::string& name, int value);
const std::string& name, int value);
} // namespace grpc

@ -40,8 +40,8 @@ typedef ::grpc_impl::ServerAsyncWriter<ByteBuffer> GenericServerAsyncWriter;
class GenericServerContext final : public ::grpc_impl::ServerContext {
public:
const grpc::string& method() const { return method_; }
const grpc::string& host() const { return host_; }
const std::string& method() const { return method_; }
const std::string& host() const { return host_; }
private:
friend class grpc_impl::Server;
@ -53,8 +53,8 @@ class GenericServerContext final : public ::grpc_impl::ServerContext {
::grpc_impl::ServerContext::Clear();
}
grpc::string method_;
grpc::string host_;
std::string method_;
std::string host_;
};
// A generic service at the server side accepts all RPC methods and hosts. It is
@ -102,8 +102,8 @@ using ServerGenericBidiReactor =
class GenericCallbackServerContext final
: public ::grpc_impl::CallbackServerContext {
public:
const grpc::string& method() const { return method_; }
const grpc::string& host() const { return host_; }
const std::string& method() const { return method_; }
const std::string& host() const { return host_; }
private:
friend class ::grpc_impl::Server;
@ -115,8 +115,8 @@ class GenericCallbackServerContext final
::grpc_impl::CallbackServerContext::Clear();
}
grpc::string method_;
grpc::string host_;
std::string method_;
std::string host_;
};
/// \a CallbackGenericService is the base class for generic services implemented

@ -51,8 +51,8 @@ class CallHook;
// TODO(yangg) if the map is changed before we send, the pointers will be a
// mess. Make sure it does not happen.
inline grpc_metadata* FillMetadataArray(
const std::multimap<grpc::string, grpc::string>& metadata,
size_t* metadata_count, const grpc::string& optional_error_details) {
const std::multimap<std::string, std::string>& metadata,
size_t* metadata_count, const std::string& optional_error_details) {
*metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1);
if (*metadata_count == 0) {
return nullptr;
@ -219,7 +219,7 @@ class CallOpSendInitialMetadata {
maybe_compression_level_.is_set = false;
}
void SendInitialMetadata(std::multimap<grpc::string, grpc::string>* metadata,
void SendInitialMetadata(std::multimap<std::string, std::string>* metadata,
uint32_t flags) {
maybe_compression_level_.is_set = false;
send_ = true;
@ -275,7 +275,7 @@ class CallOpSendInitialMetadata {
bool send_;
uint32_t flags_;
size_t initial_metadata_count_;
std::multimap<grpc::string, grpc::string>* metadata_map_;
std::multimap<std::string, std::string>* metadata_map_;
grpc_metadata* initial_metadata_;
struct {
bool is_set;
@ -654,7 +654,7 @@ class CallOpServerSendStatus {
CallOpServerSendStatus() : send_status_available_(false) {}
void ServerSendStatus(
std::multimap<grpc::string, grpc::string>* trailing_metadata,
std::multimap<std::string, std::string>* trailing_metadata,
const Status& status) {
send_error_details_ = status.error_details();
metadata_map_ = trailing_metadata;
@ -708,10 +708,10 @@ class CallOpServerSendStatus {
bool hijacked_ = false;
bool send_status_available_;
grpc_status_code send_status_code_;
grpc::string send_error_details_;
grpc::string send_error_message_;
std::string send_error_details_;
std::string send_error_message_;
size_t trailing_metadata_count_;
std::multimap<grpc::string, grpc::string>* metadata_map_;
std::multimap<std::string, std::string>* metadata_map_;
grpc_metadata* trailing_metadata_;
grpc_slice error_message_slice_;
};
@ -798,9 +798,9 @@ class CallOpClientRecvStatus {
*recv_status_ =
Status(static_cast<StatusCode>(status_code_),
GRPC_SLICE_IS_EMPTY(error_message_)
? grpc::string()
: grpc::string(GRPC_SLICE_START_PTR(error_message_),
GRPC_SLICE_END_PTR(error_message_)),
? std::string()
: std::string(GRPC_SLICE_START_PTR(error_message_),
GRPC_SLICE_END_PTR(error_message_)),
metadata_map_->GetBinaryErrorDetails());
if (debug_error_string_ != nullptr) {
client_context_->set_debug_error_string(debug_error_string_);

@ -220,8 +220,7 @@ class ClientContext {
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddMetadata(const grpc::string& meta_key,
const grpc::string& meta_value);
void AddMetadata(const std::string& meta_key, const std::string& meta_value);
/// Return a collection of initial metadata key-value pairs. Note that keys
/// may happen more than once (ie, a \a std::multimap is returned).
@ -297,7 +296,7 @@ class ClientContext {
/// Set the per call authority header (see
/// https://tools.ietf.org/html/rfc7540#section-8.1.2.3).
void set_authority(const grpc::string& authority) { authority_ = authority; }
void set_authority(const std::string& authority) { authority_ = authority; }
/// Return the authentication context for the associated client call.
/// It is only valid to call this during the lifetime of the client call.
@ -364,7 +363,7 @@ class ClientContext {
/// functionality. Instead, use auth_context.
///
/// \return The call's peer URI.
grpc::string peer() const;
std::string peer() const;
/// Sets the census context.
/// It is only valid to call this before the client call is created. A common
@ -409,7 +408,7 @@ class ClientContext {
/// if status is not ok() for an RPC, this will return a detailed string
/// of the gRPC Core error that led to the failure. It should not be relied
/// upon for anything other than gaining more debug data in failure cases.
grpc::string debug_error_string() const { return debug_error_string_; }
std::string debug_error_string() const { return debug_error_string_; }
private:
// Disallow copy and assign.
@ -448,7 +447,7 @@ class ClientContext {
friend class ::grpc_impl::internal::ClientContextAccessor;
// Used by friend class CallOpClientRecvStatus
void set_debug_error_string(const grpc::string& debug_error_string) {
void set_debug_error_string(const std::string& debug_error_string) {
debug_error_string_ = debug_error_string;
}
@ -477,7 +476,7 @@ class ClientContext {
(initial_metadata_corked_ ? GRPC_INITIAL_METADATA_CORKED : 0);
}
grpc::string authority() { return authority_; }
std::string authority() { return authority_; }
void SendCancelToInterceptors();
@ -495,11 +494,11 @@ class ClientContext {
grpc_call* call_;
bool call_canceled_;
gpr_timespec deadline_;
grpc::string authority_;
std::string authority_;
std::shared_ptr<grpc_impl::CallCredentials> creds_;
mutable std::shared_ptr<const grpc::AuthContext> auth_context_;
struct census_context* census_context_;
std::multimap<grpc::string, grpc::string> send_initial_metadata_;
std::multimap<std::string, std::string> send_initial_metadata_;
mutable grpc::internal::MetadataMap recv_initial_metadata_;
mutable grpc::internal::MetadataMap trailing_metadata_;
@ -509,7 +508,7 @@ class ClientContext {
grpc_compression_algorithm compression_algorithm_;
bool initial_metadata_corked_;
grpc::string debug_error_string_;
std::string debug_error_string_;
grpc::experimental::ClientRpcInfo rpc_info_;
};

@ -19,10 +19,7 @@
#ifndef GRPCPP_IMPL_CODEGEN_CONFIG_H
#define GRPCPP_IMPL_CODEGEN_CONFIG_H
#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
#endif
/// The following macros are deprecated and appear only for users
/// with PB files generated using gRPC 1.0.x plugins. They should
@ -30,11 +27,17 @@
#define GRPC_OVERRIDE override // deprecated
#define GRPC_FINAL final // deprecated
namespace grpc {
#ifdef GRPC_CUSTOM_STRING
#warning GRPC_CUSTOM_STRING is no longer supported. Please use std::string.
#endif
typedef GRPC_CUSTOM_STRING string;
namespace grpc {
using std::to_string;
// Using grpc::string and grpc::to_string is discouraged in favor of
// std::string and std::to_string. This is only for legacy code using
// them explictly.
using std::string; // deprecated
using std::to_string; // deprecated
} // namespace grpc

@ -157,8 +157,7 @@ class InterceptorBatchMethods {
/// Returns a modifiable multimap of the initial metadata to be sent. Valid
/// for PRE_SEND_INITIAL_METADATA interceptions. A value of nullptr indicates
/// that this field is not valid.
virtual std::multimap<grpc::string, grpc::string>*
GetSendInitialMetadata() = 0;
virtual std::multimap<std::string, std::string>* GetSendInitialMetadata() = 0;
/// Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
virtual Status GetSendStatus() = 0;
@ -170,7 +169,7 @@ class InterceptorBatchMethods {
/// Returns a modifiable multimap of the trailing metadata to be sent. Valid
/// for PRE_SEND_STATUS interceptions. A value of nullptr indicates
/// that this field is not valid.
virtual std::multimap<grpc::string, grpc::string>*
virtual std::multimap<std::string, std::string>*
GetSendTrailingMetadata() = 0;
/// Returns a pointer to the modifiable received message. Note that the

@ -100,7 +100,7 @@ class InterceptorBatchMethodsImpl
bool GetSendMessageStatus() override { return !*fail_send_message_; }
std::multimap<grpc::string, grpc::string>* GetSendInitialMetadata() override {
std::multimap<std::string, std::string>* GetSendInitialMetadata() override {
return send_initial_metadata_;
}
@ -115,8 +115,7 @@ class InterceptorBatchMethodsImpl
*error_message_ = status.error_message();
}
std::multimap<grpc::string, grpc::string>* GetSendTrailingMetadata()
override {
std::multimap<std::string, std::string>* GetSendTrailingMetadata() override {
return send_trailing_metadata_;
}
@ -150,19 +149,19 @@ class InterceptorBatchMethodsImpl
}
void SetSendInitialMetadata(
std::multimap<grpc::string, grpc::string>* metadata) {
std::multimap<std::string, std::string>* metadata) {
send_initial_metadata_ = metadata;
}
void SetSendStatus(grpc_status_code* code, grpc::string* error_details,
grpc::string* error_message) {
void SetSendStatus(grpc_status_code* code, std::string* error_details,
std::string* error_message) {
code_ = code;
error_details_ = error_details;
error_message_ = error_message;
}
void SetSendTrailingMetadata(
std::multimap<grpc::string, grpc::string>* metadata) {
std::multimap<std::string, std::string>* metadata) {
send_trailing_metadata_ = metadata;
}
@ -398,13 +397,13 @@ class InterceptorBatchMethodsImpl
const void** orig_send_message_ = nullptr;
std::function<Status(const void*)> serializer_;
std::multimap<grpc::string, grpc::string>* send_initial_metadata_;
std::multimap<std::string, std::string>* send_initial_metadata_;
grpc_status_code* code_ = nullptr;
grpc::string* error_details_ = nullptr;
grpc::string* error_message_ = nullptr;
std::string* error_details_ = nullptr;
std::string* error_message_ = nullptr;
std::multimap<grpc::string, grpc::string>* send_trailing_metadata_ = nullptr;
std::multimap<std::string, std::string>* send_trailing_metadata_ = nullptr;
void* recv_message_ = nullptr;
bool* hijacked_recv_message_failed_ = nullptr;
@ -472,7 +471,7 @@ class CancelInterceptorBatchMethods
"has a Cancel notification");
}
std::multimap<grpc::string, grpc::string>* GetSendInitialMetadata() override {
std::multimap<std::string, std::string>* GetSendInitialMetadata() override {
GPR_CODEGEN_ASSERT(false &&
"It is illegal to call GetSendInitialMetadata on a "
"method which has a Cancel notification");
@ -493,8 +492,7 @@ class CancelInterceptorBatchMethods
return;
}
std::multimap<grpc::string, grpc::string>* GetSendTrailingMetadata()
override {
std::multimap<std::string, std::string>* GetSendTrailingMetadata() override {
GPR_CODEGEN_ASSERT(false &&
"It is illegal to call GetSendTrailingMetadata on a "
"method which has a Cancel notification");

@ -36,12 +36,12 @@ class MetadataMap {
~MetadataMap() { Destroy(); }
grpc::string GetBinaryErrorDetails() {
std::string GetBinaryErrorDetails() {
// if filled_, extract from the multimap for O(log(n))
if (filled_) {
auto iter = map_.find(kBinaryErrorDetailsKey);
if (iter != map_.end()) {
return grpc::string(iter->second.begin(), iter->second.length());
return std::string(iter->second.begin(), iter->second.length());
}
}
// if not yet filled, take the O(n) lookup to avoid allocating the
@ -54,13 +54,13 @@ class MetadataMap {
GRPC_SLICE_START_PTR(arr_.metadata[i].key)),
kBinaryErrorDetailsKey,
GRPC_SLICE_LENGTH(arr_.metadata[i].key)) == 0) {
return grpc::string(reinterpret_cast<const char*>(
GRPC_SLICE_START_PTR(arr_.metadata[i].value)),
GRPC_SLICE_LENGTH(arr_.metadata[i].value));
return std::string(reinterpret_cast<const char*>(
GRPC_SLICE_START_PTR(arr_.metadata[i].value)),
GRPC_SLICE_LENGTH(arr_.metadata[i].value));
}
}
}
return grpc::string();
return std::string();
}
std::multimap<grpc::string_ref, grpc::string_ref>* map() {

@ -74,19 +74,18 @@ class AuthContext {
/// It is, in general, comprised of one or more properties (in which case they
/// have the same name).
virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
virtual grpc::string GetPeerIdentityPropertyName() const = 0;
virtual std::string GetPeerIdentityPropertyName() const = 0;
/// Returns all the property values with the given name.
virtual std::vector<grpc::string_ref> FindPropertyValues(
const grpc::string& name) const = 0;
const std::string& name) const = 0;
/// Iteration over all the properties.
virtual AuthPropertyIterator begin() const = 0;
virtual AuthPropertyIterator end() const = 0;
/// Mutation functions: should only be used by an AuthMetadataProcessor.
virtual void AddProperty(const grpc::string& key,
const string_ref& value) = 0;
virtual void AddProperty(const std::string& key, const string_ref& value) = 0;
virtual bool SetPeerIdentityPropertyName(const string& name) = 0;
};

@ -151,7 +151,7 @@ class ServerContextBase {
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddInitialMetadata(const grpc::string& key, const grpc::string& value);
void AddInitialMetadata(const std::string& key, const std::string& value);
/// Add the (\a key, \a value) pair to the initial metadata
/// associated with a server call. These are made available at the client
@ -172,7 +172,7 @@ class ServerContextBase {
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddTrailingMetadata(const grpc::string& key, const grpc::string& value);
void AddTrailingMetadata(const std::string& key, const std::string& value);
/// Return whether this RPC failed before the server could provide its status
/// back to the client. This could be because of explicit API cancellation
@ -252,7 +252,7 @@ class ServerContextBase {
void set_compression_algorithm(grpc_compression_algorithm algorithm);
/// Set the serialized load reporting costs in \a cost_data for the call.
void SetLoadReportingCosts(const std::vector<grpc::string>& cost_data);
void SetLoadReportingCosts(const std::vector<std::string>& cost_data);
/// Return the authentication context for this server call.
///
@ -268,7 +268,7 @@ class ServerContextBase {
/// WARNING: this value is never authenticated or subject to any security
/// related code. It must not be used for any authentication related
/// functionality. Instead, use auth_context.
grpc::string peer() const;
std::string peer() const;
/// Get the census context associated with this server call.
const struct census_context* census_context() const;
@ -430,8 +430,8 @@ class ServerContextBase {
bool sent_initial_metadata_;
mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
mutable ::grpc::internal::MetadataMap client_metadata_;
std::multimap<grpc::string, grpc::string> initial_metadata_;
std::multimap<grpc::string, grpc::string> trailing_metadata_;
std::multimap<std::string, std::string> initial_metadata_;
std::multimap<std::string, std::string> trailing_metadata_;
bool compression_level_set_;
grpc_compression_level compression_level_;

@ -127,7 +127,7 @@ class ServerInterface : public internal::CallHook {
/// Register a service. This call does not take ownership of the service.
/// The service must exist for the lifetime of the Server instance.
virtual bool RegisterService(const grpc::string* host, Service* service) = 0;
virtual bool RegisterService(const std::string* host, Service* service) = 0;
/// Register a generic service. This call does not take ownership of the
/// service. The service must exist for the lifetime of the Server instance.
@ -172,7 +172,7 @@ class ServerInterface : public internal::CallHook {
/// \return bound port number on success, 0 on failure.
///
/// \warning It's an error to call this method on an already started server.
virtual int AddListeningPort(const grpc::string& addr,
virtual int AddListeningPort(const std::string& addr,
grpc_impl::ServerCredentials* creds) = 0;
/// Start the server.

@ -58,7 +58,7 @@ class Slice final {
reinterpret_cast<const char*>(buf), len)) {}
/// Construct a slice from a copied string
Slice(const grpc::string& str)
Slice(const std::string& str)
: slice_(g_core_codegen_interface->grpc_slice_from_copied_buffer(
str.c_str(), str.length())) {}
@ -123,17 +123,17 @@ inline grpc::string_ref StringRefFromSlice(const grpc_slice* slice) {
GRPC_SLICE_LENGTH(*slice));
}
inline grpc::string StringFromCopiedSlice(grpc_slice slice) {
return grpc::string(reinterpret_cast<char*>(GRPC_SLICE_START_PTR(slice)),
GRPC_SLICE_LENGTH(slice));
inline std::string StringFromCopiedSlice(grpc_slice slice) {
return std::string(reinterpret_cast<char*>(GRPC_SLICE_START_PTR(slice)),
GRPC_SLICE_LENGTH(slice));
}
inline grpc_slice SliceReferencingString(const grpc::string& str) {
inline grpc_slice SliceReferencingString(const std::string& str) {
return g_core_codegen_interface->grpc_slice_from_static_buffer(str.data(),
str.length());
}
inline grpc_slice SliceFromCopiedString(const grpc::string& str) {
inline grpc_slice SliceFromCopiedString(const std::string& str) {
return g_core_codegen_interface->grpc_slice_from_copied_buffer(str.data(),
str.length());
}

@ -88,14 +88,14 @@ class Status {
/// Construct an instance with associated \a code and \a error_message.
/// It is an error to construct an OK status with non-empty \a error_message.
Status(StatusCode code, const grpc::string& error_message)
Status(StatusCode code, const std::string& error_message)
: code_(code), error_message_(error_message) {}
/// Construct an instance with \a code, \a error_message and
/// \a error_details. It is an error to construct an OK status with non-empty
/// \a error_message and/or \a error_details.
Status(StatusCode code, const grpc::string& error_message,
const grpc::string& error_details)
Status(StatusCode code, const std::string& error_message,
const std::string& error_details)
: code_(code),
error_message_(error_message),
binary_error_details_(error_details) {}
@ -109,10 +109,10 @@ class Status {
/// Return the instance's error code.
StatusCode error_code() const { return code_; }
/// Return the instance's error message.
grpc::string error_message() const { return error_message_; }
std::string error_message() const { return error_message_; }
/// Return the (binary) error details.
// Usually it contains a serialized google.rpc.Status proto.
grpc::string error_details() const { return binary_error_details_; }
std::string error_details() const { return binary_error_details_; }
/// Is the status OK?
bool ok() const { return code_ == StatusCode::OK; }
@ -124,8 +124,8 @@ class Status {
private:
StatusCode code_;
grpc::string error_message_;
grpc::string binary_error_details_;
std::string error_message_;
std::string binary_error_details_;
};
} // namespace grpc

@ -59,7 +59,7 @@ class string_ref {
string_ref(const char* s) : data_(s), length_(strlen(s)) {}
string_ref(const char* s, size_t l) : data_(s), length_(l) {}
string_ref(const grpc::string& s) : data_(s.data()), length_(s.length()) {}
string_ref(const std::string& s) : data_(s.data()), length_(s.length()) {}
/// iterators
const_iterator begin() const { return data_; }
@ -138,7 +138,7 @@ inline bool operator>(string_ref x, string_ref y) { return x.compare(y) > 0; }
inline bool operator>=(string_ref x, string_ref y) { return x.compare(y) >= 0; }
inline std::ostream& operator<<(std::ostream& out, const string_ref& string) {
return out << grpc::string(string.begin(), string.end());
return out << std::string(string.begin(), string.end());
}
} // namespace grpc

@ -38,7 +38,7 @@ class ServerBuilder;
class ServerBuilderPlugin {
public:
virtual ~ServerBuilderPlugin() {}
virtual grpc::string name() = 0;
virtual std::string name() = 0;
/// UpdateServerBuilder will be called at an early stage in
/// ServerBuilder::BuildAndStart(), right after the ServerBuilderOptions have
@ -54,7 +54,7 @@ class ServerBuilderPlugin {
/// ChangeArguments is an interface that can be used in
/// ServerBuilderOption::UpdatePlugins
virtual void ChangeArguments(const grpc::string& name, void* value) = 0;
virtual void ChangeArguments(const std::string& name, void* value) = 0;
/// UpdateChannelArguments will be called in ServerBuilder::BuildAndStart(),
/// before the Server instance is created.

@ -43,7 +43,7 @@ class ServerInitializer {
return true;
}
const std::vector<grpc::string>* GetServiceList() {
const std::vector<std::string>* GetServiceList() {
return &server_->services_;
}

@ -34,7 +34,7 @@ namespace grpc {
class ResourceQuota final : private ::grpc::GrpcLibraryCodegen {
public:
/// \param name - a unique name for this ResourceQuota.
explicit ResourceQuota(const grpc::string& name);
explicit ResourceQuota(const std::string& name);
ResourceQuota();
~ResourceQuota();

@ -34,7 +34,7 @@ namespace grpc_impl {
class ResourceQuota final : private ::grpc::GrpcLibraryCodegen {
public:
/// \param name - a unique name for this ResourceQuota.
explicit ResourceQuota(const grpc::string& name);
explicit ResourceQuota(const std::string& name);
ResourceQuota();
~ResourceQuota();

@ -44,19 +44,19 @@ class AltsContext {
AltsContext& operator=(const AltsContext&) = default;
AltsContext(const AltsContext&) = default;
grpc::string application_protocol() const;
grpc::string record_protocol() const;
grpc::string peer_service_account() const;
grpc::string local_service_account() const;
std::string application_protocol() const;
std::string record_protocol() const;
std::string peer_service_account() const;
std::string local_service_account() const;
grpc_security_level security_level() const;
RpcProtocolVersions peer_rpc_versions() const;
private:
// TODO(ZhenLian): Also plumb field peer_attributes when it is in use
grpc::string application_protocol_;
grpc::string record_protocol_;
grpc::string peer_service_account_;
grpc::string local_service_account_;
std::string application_protocol_;
std::string record_protocol_;
std::string peer_service_account_;
std::string local_service_account_;
grpc_security_level security_level_ = GRPC_SECURITY_NONE;
RpcProtocolVersions peer_rpc_versions_ = {{0, 0}, {0, 0}};
};

@ -33,7 +33,7 @@ namespace grpc_impl {
class AuthMetadataProcessor {
public:
typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata;
typedef std::multimap<grpc::string, grpc::string> OutputMetadata;
typedef std::multimap<std::string, std::string> OutputMetadata;
virtual ~AuthMetadataProcessor() {}

@ -51,25 +51,25 @@ constexpr long kMaxAuthTokenLifetimeSecs =
static inline std::shared_ptr<grpc_impl::CallCredentials>
ServiceAccountJWTAccessCredentials(
const grpc::string& json_key,
const std::string& json_key,
long token_lifetime_seconds = grpc::kMaxAuthTokenLifetimeSecs) {
return ::grpc_impl::ServiceAccountJWTAccessCredentials(
json_key, token_lifetime_seconds);
}
static inline std::shared_ptr<grpc_impl::CallCredentials>
GoogleRefreshTokenCredentials(const grpc::string& json_refresh_token) {
GoogleRefreshTokenCredentials(const std::string& json_refresh_token) {
return ::grpc_impl::GoogleRefreshTokenCredentials(json_refresh_token);
}
static inline std::shared_ptr<grpc_impl::CallCredentials>
AccessTokenCredentials(const grpc::string& access_token) {
AccessTokenCredentials(const std::string& access_token) {
return ::grpc_impl::AccessTokenCredentials(access_token);
}
static inline std::shared_ptr<grpc_impl::CallCredentials> GoogleIAMCredentials(
const grpc::string& authorization_token,
const grpc::string& authority_selector) {
const std::string& authorization_token,
const std::string& authority_selector) {
return ::grpc_impl::GoogleIAMCredentials(authorization_token,
authority_selector);
}
@ -104,7 +104,7 @@ namespace experimental {
typedef ::grpc_impl::experimental::StsCredentialsOptions StsCredentialsOptions;
static inline grpc::Status StsCredentialsOptionsFromJson(
const grpc::string& json_string, StsCredentialsOptions* options) {
const std::string& json_string, StsCredentialsOptions* options) {
return ::grpc_impl::experimental::StsCredentialsOptionsFromJson(json_string,
options);
}

@ -43,14 +43,12 @@ class SecureCallCredentials;
class SecureChannelCredentials;
std::shared_ptr<Channel> CreateCustomChannelImpl(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const std::string& target, const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args);
namespace experimental {
std::shared_ptr<Channel> CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const std::string& target, const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args,
std::vector<
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
@ -77,13 +75,13 @@ class ChannelCredentials : private grpc::GrpcLibraryCodegen {
private:
friend std::shared_ptr<Channel> CreateCustomChannelImpl(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args);
friend std::shared_ptr<Channel>
grpc_impl::experimental::CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args,
std::vector<std::unique_ptr<
@ -91,12 +89,12 @@ class ChannelCredentials : private grpc::GrpcLibraryCodegen {
interceptor_creators);
virtual std::shared_ptr<Channel> CreateChannelImpl(
const grpc::string& target, const ChannelArguments& args) = 0;
const std::string& target, const ChannelArguments& args) = 0;
// This function should have been a pure virtual function, but it is
// implemented as a virtual function so that it does not break API.
virtual std::shared_ptr<Channel> CreateChannelWithInterceptors(
const grpc::string& /*target*/, const ChannelArguments& /*args*/,
const std::string& /*target*/, const ChannelArguments& /*args*/,
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>
/*interceptor_creators*/) {
@ -115,7 +113,7 @@ class CallCredentials : private grpc::GrpcLibraryCodegen {
/// Apply this instance's credentials to \a call.
virtual bool ApplyToCall(grpc_call* call) = 0;
virtual grpc::string DebugString() {
virtual std::string DebugString() {
return "CallCredentials did not provide a debug string";
}
@ -138,16 +136,16 @@ struct SslCredentialsOptions {
/// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
/// environment variable pointing to a file on the file system containing the
/// roots.
grpc::string pem_root_certs;
std::string pem_root_certs;
/// The buffer containing the PEM encoding of the client's private key. This
/// parameter can be empty if the client does not have a private key.
grpc::string pem_private_key;
std::string pem_private_key;
/// The buffer containing the PEM encoding of the client's certificate chain.
/// This parameter can be empty if the client does not have a certificate
/// chain.
grpc::string pem_cert_chain;
std::string pem_cert_chain;
};
// Factories for building different types of Credentials The functions may
@ -183,7 +181,7 @@ constexpr long kMaxAuthTokenLifetimeSecs = 3600;
/// (JWT) created with this credentials. It should not exceed
/// \a kMaxAuthTokenLifetimeSecs or will be cropped to this value.
std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials(
const grpc::string& json_key,
const std::string& json_key,
long token_lifetime_seconds = grpc_impl::kMaxAuthTokenLifetimeSecs);
/// Builds refresh token credentials.
@ -195,7 +193,7 @@ std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials(
/// service being able to impersonate your client for requests to Google
/// services.
std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials(
const grpc::string& json_refresh_token);
const std::string& json_refresh_token);
/// Builds access token credentials.
/// access_token is an oauth2 access token that was fetched using an out of band
@ -206,7 +204,7 @@ std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials(
/// service being able to impersonate your client for requests to Google
/// services.
std::shared_ptr<CallCredentials> AccessTokenCredentials(
const grpc::string& access_token);
const std::string& access_token);
/// Builds IAM credentials.
///
@ -215,8 +213,8 @@ std::shared_ptr<CallCredentials> AccessTokenCredentials(
/// service being able to impersonate your client for requests to Google
/// services.
std::shared_ptr<CallCredentials> GoogleIAMCredentials(
const grpc::string& authorization_token,
const grpc::string& authority_selector);
const std::string& authorization_token,
const std::string& authority_selector);
/// Combines a channel credentials and a call credentials into a composite
/// channel credentials.
@ -252,9 +250,9 @@ class MetadataCredentialsPlugin {
virtual grpc::Status GetMetadata(
grpc::string_ref service_url, grpc::string_ref method_name,
const grpc::AuthContext& channel_auth_context,
std::multimap<grpc::string, grpc::string>* metadata) = 0;
std::multimap<std::string, std::string>* metadata) = 0;
virtual grpc::string DebugString() {
virtual std::string DebugString() {
return "MetadataCredentialsPlugin did not provide a debug string";
}
};
@ -270,15 +268,15 @@ namespace experimental {
/// caller to ensure that the subject and actor tokens are refreshed on disk at
/// the specified paths.
struct StsCredentialsOptions {
grpc::string token_exchange_service_uri; // Required.
grpc::string resource; // Optional.
grpc::string audience; // Optional.
grpc::string scope; // Optional.
grpc::string requested_token_type; // Optional.
grpc::string subject_token_path; // Required.
grpc::string subject_token_type; // Required.
grpc::string actor_token_path; // Optional.
grpc::string actor_token_type; // Optional.
std::string token_exchange_service_uri; // Required.
std::string resource; // Optional.
std::string audience; // Optional.
std::string scope; // Optional.
std::string requested_token_type; // Optional.
std::string subject_token_path; // Required.
std::string subject_token_type; // Required.
std::string actor_token_path; // Optional.
std::string actor_token_type; // Optional.
};
/// Creates STS Options from a JSON string. The JSON schema is as follows:
@ -317,7 +315,7 @@ struct StsCredentialsOptions {
/// }
/// }
/// }
grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string,
grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string,
StsCredentialsOptions* options);
/// Creates STS credentials options from the $STS_CREDENTIALS environment
@ -337,7 +335,7 @@ struct AltsCredentialsOptions {
/// service accounts of target endpoint that will be acceptable
/// by the client. If service accounts are provided and none of them matches
/// that of the server, authentication will fail.
std::vector<grpc::string> target_service_accounts;
std::vector<std::string> target_service_accounts;
};
/// Builds ALTS Credentials given ALTS specific options

@ -40,10 +40,10 @@ struct SslServerCredentialsOptions {
: force_client_auth(false), client_certificate_request(request_type) {}
struct PemKeyCertPair {
grpc::string private_key;
grpc::string cert_chain;
std::string private_key;
std::string cert_chain;
};
grpc::string pem_root_certs;
std::string pem_root_certs;
std::vector<PemKeyCertPair> pem_key_cert_pairs;
/// \warning Deprecated
bool force_client_auth;

@ -54,8 +54,7 @@ class ServerCredentials {
///
/// \return bound port number on success, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const grpc::string& addr,
grpc_server* server) = 0;
virtual int AddPortToServer(const std::string& addr, grpc_server* server) = 0;
};
/// Builds SSL ServerCredentials given SSL specific options

@ -44,12 +44,12 @@ namespace experimental {
class TlsKeyMaterialsConfig {
public:
struct PemKeyCertPair {
grpc::string private_key;
grpc::string cert_chain;
std::string private_key;
std::string cert_chain;
};
/** Getters for member fields. **/
const grpc::string pem_root_certs() const { return pem_root_certs_; }
const std::string pem_root_certs() const { return pem_root_certs_; }
const std::vector<PemKeyCertPair>& pem_key_cert_pair_list() const {
return pem_key_cert_pair_list_;
}
@ -57,17 +57,17 @@ class TlsKeyMaterialsConfig {
/** Setter for key materials that will be called by the user. Ownership of the
* arguments will not be transferred. **/
void set_pem_root_certs(const grpc::string& pem_root_certs);
void set_pem_root_certs(const std::string& pem_root_certs);
void add_pem_key_cert_pair(const PemKeyCertPair& pem_key_cert_pair);
void set_key_materials(
const grpc::string& pem_root_certs,
const std::string& pem_root_certs,
const std::vector<PemKeyCertPair>& pem_key_cert_pair_list);
void set_version(int version) { version_ = version; };
private:
int version_ = 0;
std::vector<PemKeyCertPair> pem_key_cert_pair_list_;
grpc::string pem_root_certs_;
std::string pem_root_certs_;
};
/** TLS credential reload arguments, wraps grpc_tls_credential_reload_arg. It is
@ -90,21 +90,21 @@ class TlsCredentialReloadArg {
void* cb_user_data() const;
bool is_pem_key_cert_pair_list_empty() const;
grpc_ssl_certificate_config_reload_status status() const;
grpc::string error_details() const;
std::string error_details() const;
/** Setters for member fields. Ownership of the arguments will not be
* transferred. **/
void set_cb_user_data(void* cb_user_data);
void set_pem_root_certs(const grpc::string& pem_root_certs);
void set_pem_root_certs(const std::string& pem_root_certs);
void add_pem_key_cert_pair(
const TlsKeyMaterialsConfig::PemKeyCertPair& pem_key_cert_pair);
void set_key_materials(const grpc::string& pem_root_certs,
void set_key_materials(const std::string& pem_root_certs,
std::vector<TlsKeyMaterialsConfig::PemKeyCertPair>
pem_key_cert_pair_list);
void set_key_materials_config(
const std::shared_ptr<TlsKeyMaterialsConfig>& key_materials_config);
void set_status(grpc_ssl_certificate_config_reload_status status);
void set_error_details(const grpc::string& error_details);
void set_error_details(const std::string& error_details);
/** Calls the C arg's callback function. **/
void OnCredentialReloadDoneCallback();
@ -187,20 +187,20 @@ class TlsServerAuthorizationCheckArg {
/** Getters for member fields. **/
void* cb_user_data() const;
int success() const;
grpc::string target_name() const;
grpc::string peer_cert() const;
grpc::string peer_cert_full_chain() const;
std::string target_name() const;
std::string peer_cert() const;
std::string peer_cert_full_chain() const;
grpc_status_code status() const;
grpc::string error_details() const;
std::string error_details() const;
/** Setters for member fields. **/
void set_cb_user_data(void* cb_user_data);
void set_success(int success);
void set_target_name(const grpc::string& target_name);
void set_peer_cert(const grpc::string& peer_cert);
void set_peer_cert_full_chain(const grpc::string& peer_cert_full_chain);
void set_target_name(const std::string& target_name);
void set_peer_cert(const std::string& peer_cert);
void set_peer_cert_full_chain(const std::string& peer_cert_full_chain);
void set_status(grpc_status_code status);
void set_error_details(const grpc::string& error_details);
void set_error_details(const std::string& error_details);
/** Calls the C arg's callback function. **/
void OnServerAuthorizationCheckDoneCallback();

@ -129,7 +129,7 @@ class ServerBuilder {
/// it is successfully bound by BuildAndStart(), 0 otherwise. AddListeningPort
/// does not modify this pointer.
ServerBuilder& AddListeningPort(
const grpc::string& addr_uri,
const std::string& addr_uri,
std::shared_ptr<grpc_impl::ServerCredentials> creds,
int* selected_port = nullptr);
@ -173,7 +173,7 @@ class ServerBuilder {
/// The service must exist for the lifetime of the \a Server instance
/// returned by \a BuildAndStart(). Only matches requests with :authority \a
/// host
ServerBuilder& RegisterService(const grpc::string& host,
ServerBuilder& RegisterService(const std::string& host,
grpc::Service* service);
/// Register a generic service.
@ -242,7 +242,7 @@ class ServerBuilder {
/// Add a channel argument (an escape hatch to tuning core library parameters
/// directly)
template <class T>
ServerBuilder& AddChannelArgument(const grpc::string& arg, const T& value) {
ServerBuilder& AddChannelArgument(const std::string& arg, const T& value) {
return SetOption(grpc::MakeChannelArgumentOption(arg, value));
}
@ -311,17 +311,17 @@ class ServerBuilder {
protected:
/// Experimental, to be deprecated
struct Port {
grpc::string addr;
std::string addr;
std::shared_ptr<grpc_impl::ServerCredentials> creds;
int* selected_port;
};
/// Experimental, to be deprecated
typedef std::unique_ptr<grpc::string> HostString;
typedef std::unique_ptr<std::string> HostString;
struct NamedService {
explicit NamedService(grpc::Service* s) : service(s) {}
NamedService(const grpc::string& h, grpc::Service* s)
: host(new grpc::string(h)), service(s) {}
NamedService(const std::string& h, grpc::Service* s)
: host(new std::string(h)), service(s) {}
HostString host;
grpc::Service* service;
};

@ -0,0 +1,417 @@
/*
*
* Copyright 2015-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.
*
*/
#ifndef GRPCPP_SERVER_BUILDER_IMPL_H
#define GRPCPP_SERVER_BUILDER_IMPL_H
#include <climits>
#include <map>
#include <memory>
#include <vector>
#include <grpc/impl/codegen/port_platform.h>
#include <grpc/compression.h>
#include <grpc/support/cpu.h>
#include <grpc/support/workaround_list.h>
#include <grpcpp/impl/channel_argument_option.h>
#include <grpcpp/impl/codegen/server_interceptor.h>
#include <grpcpp/impl/server_builder_option.h>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/server.h>
#include <grpcpp/support/config.h>
struct grpc_resource_quota;
namespace grpc_impl {
class CompletionQueue;
class Server;
class ServerCompletionQueue;
class ServerCredentials;
} // namespace grpc_impl
namespace grpc {
class AsyncGenericService;
class ResourceQuota;
class Service;
namespace testing {
class ServerBuilderPluginTest;
} // namespace testing
namespace internal {
class ExternalConnectionAcceptorImpl;
} // namespace internal
#ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
namespace experimental {
#endif
class CallbackGenericService;
#ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
} // namespace experimental
#endif
namespace experimental {
// EXPERIMENTAL API:
// Interface for a grpc server to build transports with connections created out
// of band.
// See ServerBuilder's AddExternalConnectionAcceptor API.
class ExternalConnectionAcceptor {
public:
struct NewConnectionParameters {
int listener_fd = -1;
int fd = -1;
ByteBuffer read_buffer; // data intended for the grpc server
};
virtual ~ExternalConnectionAcceptor() {}
// If called before grpc::Server is started or after it is shut down, the new
// connection will be closed.
virtual void HandleNewConnection(NewConnectionParameters* p) = 0;
};
} // namespace experimental
} // namespace grpc
namespace grpc_impl {
/// A builder class for the creation and startup of \a grpc::Server instances.
class ServerBuilder {
public:
ServerBuilder();
virtual ~ServerBuilder();
//////////////////////////////////////////////////////////////////////////////
// Primary API's
/// Return a running server which is ready for processing calls.
/// Before calling, one typically needs to ensure that:
/// 1. a service is registered - so that the server knows what to serve
/// (via RegisterService, or RegisterAsyncGenericService)
/// 2. a listening port has been added - so the server knows where to receive
/// traffic (via AddListeningPort)
/// 3. [for async api only] completion queues have been added via
/// AddCompletionQueue
///
/// Will return a nullptr on errors.
virtual std::unique_ptr<grpc::Server> BuildAndStart();
/// Register a service. This call does not take ownership of the service.
/// The service must exist for the lifetime of the \a Server instance returned
/// by \a BuildAndStart().
/// Matches requests with any :authority
ServerBuilder& RegisterService(grpc::Service* service);
/// Enlists an endpoint \a addr (port with an optional IP address) to
/// bind the \a grpc::Server object to be created to.
///
/// It can be invoked multiple times.
///
/// \param addr_uri The address to try to bind to the server in URI form. If
/// the scheme name is omitted, "dns:///" is assumed. To bind to any address,
/// please use IPv6 any, i.e., [::]:<port>, which also accepts IPv4
/// connections. Valid values include dns:///localhost:1234, /
/// 192.168.1.1:31416, dns:///[::1]:27182, etc.).
/// \param creds The credentials associated with the server.
/// \param selected_port[out] If not `nullptr`, gets populated with the port
/// number bound to the \a grpc::Server for the corresponding endpoint after
/// it is successfully bound by BuildAndStart(), 0 otherwise. AddListeningPort
/// does not modify this pointer.
ServerBuilder& AddListeningPort(
const std::string& addr_uri,
std::shared_ptr<grpc_impl::ServerCredentials> creds,
int* selected_port = nullptr);
/// Add a completion queue for handling asynchronous services.
///
/// Best performance is typically obtained by using one thread per polling
/// completion queue.
///
/// Caller is required to shutdown the server prior to shutting down the
/// returned completion queue. Caller is also required to drain the
/// completion queue after shutting it down. A typical usage scenario:
///
/// // While building the server:
/// ServerBuilder builder;
/// ...
/// cq_ = builder.AddCompletionQueue();
/// server_ = builder.BuildAndStart();
///
/// // While shutting down the server;
/// server_->Shutdown();
/// cq_->Shutdown(); // Always *after* the associated server's Shutdown()!
/// // Drain the cq_ that was created
/// void* ignored_tag;
/// bool ignored_ok;
/// while (cq_->Next(&ignored_tag, &ignored_ok)) { }
///
/// \param is_frequently_polled This is an optional parameter to inform gRPC
/// library about whether this completion queue would be frequently polled
/// (i.e. by calling \a Next() or \a AsyncNext()). The default value is
/// 'true' and is the recommended setting. Setting this to 'false' (i.e.
/// not polling the completion queue frequently) will have a significantly
/// negative performance impact and hence should not be used in production
/// use cases.
std::unique_ptr<grpc_impl::ServerCompletionQueue> AddCompletionQueue(
bool is_frequently_polled = true);
//////////////////////////////////////////////////////////////////////////////
// Less commonly used RegisterService variants
/// Register a service. This call does not take ownership of the service.
/// The service must exist for the lifetime of the \a Server instance
/// returned by \a BuildAndStart(). Only matches requests with :authority \a
/// host
ServerBuilder& RegisterService(const std::string& host,
grpc::Service* service);
/// Register a generic service.
/// Matches requests with any :authority
/// This is mostly useful for writing generic gRPC Proxies where the exact
/// serialization format is unknown
ServerBuilder& RegisterAsyncGenericService(
grpc::AsyncGenericService* service);
//////////////////////////////////////////////////////////////////////////////
// Fine control knobs
/// Set max receive message size in bytes.
/// The default is GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH.
ServerBuilder& SetMaxReceiveMessageSize(int max_receive_message_size) {
max_receive_message_size_ = max_receive_message_size;
return *this;
}
/// Set max send message size in bytes.
/// The default is GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH.
ServerBuilder& SetMaxSendMessageSize(int max_send_message_size) {
max_send_message_size_ = max_send_message_size;
return *this;
}
/// \deprecated For backward compatibility.
ServerBuilder& SetMaxMessageSize(int max_message_size) {
return SetMaxReceiveMessageSize(max_message_size);
}
/// Set the support status for compression algorithms. All algorithms are
/// enabled by default.
///
/// Incoming calls compressed with an unsupported algorithm will fail with
/// \a GRPC_STATUS_UNIMPLEMENTED.
ServerBuilder& SetCompressionAlgorithmSupportStatus(
grpc_compression_algorithm algorithm, bool enabled);
/// The default compression level to use for all channel calls in the
/// absence of a call-specific level.
ServerBuilder& SetDefaultCompressionLevel(grpc_compression_level level);
/// The default compression algorithm to use for all channel calls in the
/// absence of a call-specific level. Note that it overrides any compression
/// level set by \a SetDefaultCompressionLevel.
ServerBuilder& SetDefaultCompressionAlgorithm(
grpc_compression_algorithm algorithm);
/// Set the attached buffer pool for this server
ServerBuilder& SetResourceQuota(const grpc::ResourceQuota& resource_quota);
ServerBuilder& SetOption(std::unique_ptr<grpc::ServerBuilderOption> option);
/// Options for synchronous servers.
enum SyncServerOption {
NUM_CQS, ///< Number of completion queues.
MIN_POLLERS, ///< Minimum number of polling threads.
MAX_POLLERS, ///< Maximum number of polling threads.
CQ_TIMEOUT_MSEC ///< Completion queue timeout in milliseconds.
};
/// Only useful if this is a Synchronous server.
ServerBuilder& SetSyncServerOption(SyncServerOption option, int value);
/// Add a channel argument (an escape hatch to tuning core library parameters
/// directly)
template <class T>
ServerBuilder& AddChannelArgument(const std::string& arg, const T& value) {
return SetOption(grpc::MakeChannelArgumentOption(arg, value));
}
/// For internal use only: Register a ServerBuilderPlugin factory function.
static void InternalAddPluginFactory(
std::unique_ptr<grpc::ServerBuilderPlugin> (*CreatePlugin)());
/// Enable a server workaround. Do not use unless you know what the workaround
/// does. For explanation and detailed descriptions of workarounds, see
/// doc/workarounds.md.
ServerBuilder& EnableWorkaround(grpc_workaround_list id);
/// NOTE: class experimental_type is not part of the public API of this class.
/// TODO(yashykt): Integrate into public API when this is no longer
/// experimental.
class experimental_type {
public:
explicit experimental_type(grpc_impl::ServerBuilder* builder)
: builder_(builder) {}
void SetInterceptorCreators(
std::vector<std::unique_ptr<
grpc::experimental::ServerInterceptorFactoryInterface>>
interceptor_creators) {
builder_->interceptor_creators_ = std::move(interceptor_creators);
}
#ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
/// Register a generic service that uses the callback API.
/// Matches requests with any :authority
/// This is mostly useful for writing generic gRPC Proxies where the exact
/// serialization format is unknown
ServerBuilder& RegisterCallbackGenericService(
grpc::experimental::CallbackGenericService* service);
#endif
enum class ExternalConnectionType {
FROM_FD = 0 // in the form of a file descriptor
};
/// Register an acceptor to handle the externally accepted connection in
/// grpc server. The returned acceptor can be used to pass the connection
/// to grpc server, where a channel will be created with the provided
/// server credentials.
std::unique_ptr<grpc::experimental::ExternalConnectionAcceptor>
AddExternalConnectionAcceptor(ExternalConnectionType type,
std::shared_ptr<ServerCredentials> creds);
private:
ServerBuilder* builder_;
};
#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
/// Register a generic service that uses the callback API.
/// Matches requests with any :authority
/// This is mostly useful for writing generic gRPC Proxies where the exact
/// serialization format is unknown
ServerBuilder& RegisterCallbackGenericService(
grpc::CallbackGenericService* service);
#endif
/// NOTE: The function experimental() is not stable public API. It is a view
/// to the experimental components of this class. It may be changed or removed
/// at any time.
experimental_type experimental() { return experimental_type(this); }
protected:
/// Experimental, to be deprecated
struct Port {
std::string addr;
std::shared_ptr<grpc_impl::ServerCredentials> creds;
int* selected_port;
};
/// Experimental, to be deprecated
typedef std::unique_ptr<std::string> HostString;
struct NamedService {
explicit NamedService(grpc::Service* s) : service(s) {}
NamedService(const std::string& h, grpc::Service* s)
: host(new std::string(h)), service(s) {}
HostString host;
grpc::Service* service;
};
/// Experimental, to be deprecated
std::vector<Port> ports() { return ports_; }
/// Experimental, to be deprecated
std::vector<NamedService*> services() {
std::vector<NamedService*> service_refs;
for (auto& ptr : services_) {
service_refs.push_back(ptr.get());
}
return service_refs;
}
/// Experimental, to be deprecated
std::vector<grpc::ServerBuilderOption*> options() {
std::vector<grpc::ServerBuilderOption*> option_refs;
for (auto& ptr : options_) {
option_refs.push_back(ptr.get());
}
return option_refs;
}
private:
friend class ::grpc::testing::ServerBuilderPluginTest;
struct SyncServerSettings {
SyncServerSettings()
: num_cqs(1), min_pollers(1), max_pollers(2), cq_timeout_msec(10000) {}
/// Number of server completion queues to create to listen to incoming RPCs.
int num_cqs;
/// Minimum number of threads per completion queue that should be listening
/// to incoming RPCs.
int min_pollers;
/// Maximum number of threads per completion queue that can be listening to
/// incoming RPCs.
int max_pollers;
/// The timeout for server completion queue's AsyncNext call.
int cq_timeout_msec;
};
int max_receive_message_size_;
int max_send_message_size_;
std::vector<std::unique_ptr<grpc::ServerBuilderOption>> options_;
std::vector<std::unique_ptr<NamedService>> services_;
std::vector<Port> ports_;
SyncServerSettings sync_server_settings_;
/// List of completion queues added via \a AddCompletionQueue method.
std::vector<grpc_impl::ServerCompletionQueue*> cqs_;
std::shared_ptr<grpc_impl::ServerCredentials> creds_;
std::vector<std::unique_ptr<grpc::ServerBuilderPlugin>> plugins_;
grpc_resource_quota* resource_quota_;
grpc::AsyncGenericService* generic_service_{nullptr};
#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
grpc::CallbackGenericService* callback_generic_service_{nullptr};
#else
grpc::experimental::CallbackGenericService* callback_generic_service_{
nullptr};
#endif
struct {
bool is_set;
grpc_compression_level level;
} maybe_default_compression_level_;
struct {
bool is_set;
grpc_compression_algorithm algorithm;
} maybe_default_compression_algorithm_;
uint32_t enabled_compression_algorithms_bitset_;
std::vector<
std::unique_ptr<grpc::experimental::ServerInterceptorFactoryInterface>>
interceptor_creators_;
std::vector<std::shared_ptr<grpc::internal::ExternalConnectionAcceptorImpl>>
acceptors_;
};
} // namespace grpc_impl
#endif // GRPCPP_SERVER_BUILDER_IMPL_H

@ -89,7 +89,7 @@ class Server : public grpc::ServerInterface, private grpc::GrpcLibraryCodegen {
/// Called before server is started.
virtual void PreServerStart(Server* /*server*/) {}
/// Called after a server port is added.
virtual void AddPort(Server* /*server*/, const grpc::string& /*addr*/,
virtual void AddPort(Server* /*server*/, const std::string& /*addr*/,
grpc::ServerCredentials* /*creds*/, int /*port*/) {}
};
/// Set the global callback object. Can only be called once per application.
@ -138,7 +138,7 @@ class Server : public grpc::ServerInterface, private grpc::GrpcLibraryCodegen {
protected:
/// Register a service. This call does not take ownership of the service.
/// The service must exist for the lifetime of the Server instance.
bool RegisterService(const grpc::string* host,
bool RegisterService(const std::string* host,
grpc::Service* service) override;
/// Try binding the server to the given \a addr endpoint
@ -154,7 +154,7 @@ class Server : public grpc::ServerInterface, private grpc::GrpcLibraryCodegen {
/// \return bound port number on success, 0 on failure.
///
/// \warning It is an error to call this method on an already started server.
int AddListeningPort(const grpc::string& addr,
int AddListeningPort(const std::string& addr,
grpc::ServerCredentials* creds) override;
/// NOTE: This is *NOT* a public API. The server constructors are supposed to
@ -341,7 +341,7 @@ class Server : public grpc::ServerInterface, private grpc::GrpcLibraryCodegen {
std::shared_ptr<GlobalCallbacks> global_callbacks_;
std::vector<grpc::string> services_;
std::vector<std::string> services_;
bool has_async_generic_service_ = false;
bool has_callback_generic_service_ = false;
bool has_callback_methods_ = false;

@ -63,7 +63,7 @@ class ChannelArguments {
// gRPC specific channel argument setters
/// Set target name override for SSL host name checking. This option should
/// be used with caution in production.
void SetSslTargetNameOverride(const grpc::string& name);
void SetSslTargetNameOverride(const std::string& name);
// TODO(yangg) add flow control options
/// Set the compression algorithm for the channel.
void SetCompressionAlgorithm(grpc_compression_algorithm algorithm);
@ -84,7 +84,7 @@ class ChannelArguments {
void SetSocketMutator(grpc_socket_mutator* mutator);
/// Set the string to prepend to the user agent.
void SetUserAgentPrefix(const grpc::string& user_agent_prefix);
void SetUserAgentPrefix(const std::string& user_agent_prefix);
/// Set the buffer pool to be attached to the constructed channel.
void SetResourceQuota(const grpc::ResourceQuota& resource_quota);
@ -96,25 +96,25 @@ class ChannelArguments {
/// Set LB policy name.
/// Note that if the name resolver returns only balancer addresses, the
/// grpclb LB policy will be used, regardless of what is specified here.
void SetLoadBalancingPolicyName(const grpc::string& lb_policy_name);
void SetLoadBalancingPolicyName(const std::string& lb_policy_name);
/// Set service config in JSON form.
/// Primarily meant for use in unit tests.
void SetServiceConfigJSON(const grpc::string& service_config_json);
void SetServiceConfigJSON(const std::string& service_config_json);
// Generic channel argument setters. Only for advanced use cases.
/// Set an integer argument \a value under \a key.
void SetInt(const grpc::string& key, int value);
void SetInt(const std::string& key, int value);
// Generic channel argument setter. Only for advanced use cases.
/// Set a pointer argument \a value under \a key. Owership is not transferred.
void SetPointer(const grpc::string& key, void* value);
void SetPointer(const std::string& key, void* value);
void SetPointerWithVtable(const grpc::string& key, void* value,
void SetPointerWithVtable(const std::string& key, void* value,
const grpc_arg_pointer_vtable* vtable);
/// Set a textual argument \a value under \a key.
void SetString(const grpc::string& key, const grpc::string& value);
void SetString(const std::string& key, const std::string& value);
/// Return (by value) a C \a grpc_channel_args structure which points to
/// arguments owned by this \a ChannelArguments instance
@ -141,10 +141,10 @@ class ChannelArguments {
};
// Returns empty string when it is not set.
grpc::string GetSslTargetNameOverride() const;
std::string GetSslTargetNameOverride() const;
std::vector<grpc_arg> args_;
std::list<grpc::string> strings_;
std::list<std::string> strings_;
};
} // namespace grpc_impl

@ -28,7 +28,7 @@ namespace experimental {
/// Otherwise, returns the validation error.
/// TODO(yashykt): Promote it to out of experimental once it is proved useful
/// and gRFC is accepted.
grpc::string ValidateServiceConfigJSON(const grpc::string& service_config_json);
std::string ValidateServiceConfigJSON(const std::string& service_config_json);
} // namespace experimental
} // namespace grpc

@ -33,9 +33,9 @@ class ServerContextTestSpouse {
/// Inject client metadata to the ServerContext for the test. The test spouse
/// must be alive when \a ServerContext::client_metadata is called.
void AddClientMetadata(const grpc::string& key, const grpc::string& value) {
void AddClientMetadata(const std::string& key, const std::string& value) {
client_metadata_storage_.insert(
std::pair<grpc::string, grpc::string>(key, value));
std::pair<std::string, std::string>(key, value));
ctx_->client_metadata_.map()->clear();
for (const auto& item : client_metadata_storage_) {
ctx_->client_metadata_.map()->insert(
@ -45,17 +45,17 @@ class ServerContextTestSpouse {
}
}
std::multimap<grpc::string, grpc::string> GetInitialMetadata() const {
std::multimap<std::string, std::string> GetInitialMetadata() const {
return ctx_->initial_metadata_;
}
std::multimap<grpc::string, grpc::string> GetTrailingMetadata() const {
std::multimap<std::string, std::string> GetTrailingMetadata() const {
return ctx_->trailing_metadata_;
}
private:
ServerContext* ctx_; // not owned
std::multimap<grpc::string, grpc::string> client_metadata_storage_;
std::multimap<std::string, std::string> client_metadata_storage_;
};
} // namespace testing

@ -21,14 +21,19 @@
#include "src/compiler/config_protobuf.h"
#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
#ifdef GRPC_CUSTOM_STRING
#warning GRPC_CUSTOM_STRING is no longer supported. Please use std::string.
#endif
namespace grpc {
typedef GRPC_CUSTOM_STRING string;
// Using grpc::string and grpc::to_string is discouraged in favor of
// std::string and std::to_string. This is only for legacy code using
// them explictly.
using std::string; // deprecated
using std::to_string; // deprecated
namespace protobuf {

@ -26,7 +26,7 @@ namespace grpc_cpp_generator {
namespace {
template <class T>
grpc::string as_string(T x) {
std::string as_string(T x) {
std::ostringstream out;
out << x;
return out.str();
@ -40,8 +40,8 @@ inline bool ServerOnlyStreaming(const grpc_generator::Method* method) {
return !method->ClientStreaming() && method->ServerStreaming();
}
grpc::string FilenameIdentifier(const grpc::string& filename) {
grpc::string result;
std::string FilenameIdentifier(const std::string& filename) {
std::string result;
for (unsigned i = 0; i < filename.size(); i++) {
char c = filename[i];
if (isalnum(c)) {
@ -63,9 +63,9 @@ T* array_end(T (&array)[N]) {
}
void PrintIncludes(grpc_generator::Printer* printer,
const std::vector<grpc::string>& headers,
bool use_system_headers, const grpc::string& search_path) {
std::map<grpc::string, grpc::string> vars;
const std::vector<std::string>& headers,
bool use_system_headers, const std::string& search_path) {
std::map<std::string, std::string> vars;
vars["l"] = use_system_headers ? '<' : '"';
vars["r"] = use_system_headers ? '>' : '"';
@ -83,13 +83,13 @@ void PrintIncludes(grpc_generator::Printer* printer,
}
}
grpc::string GetHeaderPrologue(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetHeaderPrologue(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
vars["filename"] = file->filename();
vars["filename_identifier"] = FilenameIdentifier(file->filename());
@ -102,7 +102,7 @@ grpc::string GetHeaderPrologue(grpc_generator::File* file,
printer->Print(vars,
"// If you make any local change, they will be lost.\n");
printer->Print(vars, "// source: $filename$\n");
grpc::string leading_comments = file->GetLeadingComments("//");
std::string leading_comments = file->GetLeadingComments("//");
if (!leading_comments.empty()) {
printer->Print(vars, "// Original file comments:\n");
printer->PrintRaw(leading_comments.c_str());
@ -118,19 +118,19 @@ grpc::string GetHeaderPrologue(grpc_generator::File* file,
}
// Convert from "a/b/c.proto" to "#include \"a/b/c$message_header_ext$\"\n"
grpc::string ImportInludeFromProtoName(const grpc::string& proto_name) {
return grpc::string("#include \"") +
std::string ImportInludeFromProtoName(const std::string& proto_name) {
return std::string("#include \"") +
proto_name.substr(0, proto_name.size() - 6) +
grpc::string("$message_header_ext$\"\n");
std::string("$message_header_ext$\"\n");
}
grpc::string GetHeaderIncludes(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetHeaderIncludes(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
if (!params.additional_header_includes.empty()) {
PrintIncludes(printer.get(), params.additional_header_includes, false,
@ -160,7 +160,7 @@ grpc::string GetHeaderIncludes(grpc_generator::File* file,
"grpcpp/impl/codegen/stub_options.h",
"grpcpp/impl/codegen/sync_stream.h",
};
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
std::vector<std::string> headers(headers_strs, array_end(headers_strs));
PrintIncludes(printer.get(), headers, params.use_system_headers,
params.grpc_search_path);
printer->Print(vars, "\n");
@ -170,17 +170,16 @@ grpc::string GetHeaderIncludes(grpc_generator::File* file,
: params.message_header_extension;
if (params.include_import_headers) {
const std::vector<grpc::string> import_names = file->GetImportNames();
const std::vector<std::string> import_names = file->GetImportNames();
for (const auto& import_name : import_names) {
const grpc::string include_name =
ImportInludeFromProtoName(import_name);
const std::string include_name = ImportInludeFromProtoName(import_name);
printer->Print(vars, include_name.c_str());
}
printer->PrintRaw("\n");
}
if (!file->package().empty()) {
std::vector<grpc::string> parts = file->package_parts();
std::vector<std::string> parts = file->package_parts();
for (auto part = parts.begin(); part != parts.end(); part++) {
vars["part"] = *part;
@ -192,17 +191,18 @@ grpc::string GetHeaderIncludes(grpc_generator::File* file,
return output;
}
void PrintHeaderClientMethodInterfaces(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars, bool is_public) {
void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<std::string, std::string>* vars,
bool is_public) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
struct {
grpc::string prefix;
grpc::string method_params; // extra arguments to method
grpc::string raw_args; // extra arguments to raw version of method
std::string prefix;
std::string method_params; // extra arguments to method
std::string raw_args; // extra arguments to raw version of method
} async_prefixes[] = {{"Async", ", void* tag", ", tag"},
{"PrepareAsync", "", ""}};
@ -392,15 +392,15 @@ void PrintHeaderClientMethodInterfaces(
void PrintHeaderClientMethod(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars,
std::map<std::string, std::string>* vars,
bool is_public) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
struct {
grpc::string prefix;
grpc::string method_params; // extra arguments to method
grpc::string raw_args; // extra arguments to raw version of method
std::string prefix;
std::string method_params; // extra arguments to method
std::string raw_args; // extra arguments to raw version of method
} async_prefixes[] = {{"Async", ", void* tag", ", tag"},
{"PrepareAsync", "", ""}};
@ -579,7 +579,7 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
void PrintHeaderClientMethodCallbackInterfacesStart(
grpc_generator::Printer* printer,
std::map<grpc::string, grpc::string>* /*vars*/) {
std::map<std::string, std::string>* /*vars*/) {
// This declares the interface for the callback-based API. The components
// are pure; even though this is new (post-1.0) API, it can be pure because
// it is an entirely new interface that happens to be scoped within
@ -594,7 +594,7 @@ void PrintHeaderClientMethodCallbackInterfacesStart(
void PrintHeaderClientMethodCallbackInterfaces(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
@ -672,7 +672,7 @@ void PrintHeaderClientMethodCallbackInterfaces(
void PrintHeaderClientMethodCallbackInterfacesEnd(
grpc_generator::Printer* printer,
std::map<grpc::string, grpc::string>* /*vars*/) {
std::map<std::string, std::string>* /*vars*/) {
printer->Outdent();
printer->Print("};\n");
printer->Print(
@ -696,7 +696,7 @@ void PrintHeaderClientMethodCallbackInterfacesEnd(
void PrintHeaderClientMethodCallbackStart(
grpc_generator::Printer* printer,
std::map<grpc::string, grpc::string>* /*vars*/) {
std::map<std::string, std::string>* /*vars*/) {
// This declares the stub entry for the callback-based API.
printer->Print("class experimental_async final :\n");
printer->Print(" public StubInterface::experimental_async_interface {\n");
@ -704,9 +704,9 @@ void PrintHeaderClientMethodCallbackStart(
printer->Indent();
}
void PrintHeaderClientMethodCallback(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
void PrintHeaderClientMethodCallback(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
@ -785,7 +785,7 @@ void PrintHeaderClientMethodCallback(
void PrintHeaderClientMethodCallbackEnd(
grpc_generator::Printer* printer,
std::map<grpc::string, grpc::string>* /*vars*/) {
std::map<std::string, std::string>* /*vars*/) {
printer->Outdent();
printer->Print(" private:\n");
printer->Indent();
@ -805,7 +805,7 @@ void PrintHeaderClientMethodCallbackEnd(
void PrintHeaderClientMethodData(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
printer->Print(*vars,
"const ::grpc::internal::RpcMethod rpcmethod_$Method$_;\n");
@ -813,7 +813,7 @@ void PrintHeaderClientMethodData(grpc_generator::Printer* printer,
void PrintHeaderServerMethodSync(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
@ -850,7 +850,7 @@ void PrintHeaderServerMethodSync(grpc_generator::Printer* printer,
// to generate async and raw async APIs.
void PrintHeaderServerAsyncMethodsHelper(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
if (method->NoStreaming()) {
printer->Print(
*vars,
@ -945,7 +945,7 @@ void PrintHeaderServerAsyncMethodsHelper(
void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
// These will be disabled
(*vars)["Request"] = method->input_type_name();
@ -980,7 +980,7 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer,
// to generate callback and raw callback APIs.
void PrintHeaderServerCallbackMethodsHelper(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
if (method->NoStreaming()) {
printer->Print(
*vars,
@ -1080,9 +1080,9 @@ void PrintHeaderServerCallbackMethodsHelper(
}
}
void PrintHeaderServerMethodCallback(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
void PrintHeaderServerMethodCallback(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
// These will be disabled
(*vars)["Request"] = method->input_type_name();
@ -1211,7 +1211,7 @@ void PrintHeaderServerMethodCallback(
void PrintHeaderServerMethodRawCallback(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
// These will be disabled
(*vars)["Request"] = method->input_type_name();
@ -1325,7 +1325,7 @@ void PrintHeaderServerMethodRawCallback(
void PrintHeaderServerMethodStreamedUnary(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
@ -1379,7 +1379,7 @@ void PrintHeaderServerMethodStreamedUnary(
void PrintHeaderServerMethodSplitStreaming(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
@ -1432,9 +1432,9 @@ void PrintHeaderServerMethodSplitStreaming(
}
}
void PrintHeaderServerMethodGeneric(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
void PrintHeaderServerMethodGeneric(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
@ -1505,7 +1505,7 @@ void PrintHeaderServerMethodGeneric(
void PrintHeaderServerMethodRaw(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
// These will be disabled
(*vars)["Request"] = method->input_type_name();
@ -1536,7 +1536,7 @@ void PrintHeaderServerMethodRaw(grpc_generator::Printer* printer,
void PrintHeaderService(grpc_generator::Printer* printer,
const grpc_generator::Service* service,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Service"] = service->name();
printer->Print(service->GetLeadingComments("//").c_str());
@ -1769,13 +1769,13 @@ void PrintHeaderService(grpc_generator::Printer* printer,
printer->Print(service->GetTrailingComments("//").c_str());
}
grpc::string GetHeaderServices(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetHeaderServices(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
// Package string is empty or ends with a dot. It is used to fully qualify
// method names.
vars["Package"] = file->package();
@ -1800,19 +1800,19 @@ grpc::string GetHeaderServices(grpc_generator::File* file,
return output;
}
grpc::string GetHeaderEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
grpc::string output;
std::string GetHeaderEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
vars["filename"] = file->filename();
vars["filename_identifier"] = FilenameIdentifier(file->filename());
if (!file->package().empty()) {
std::vector<grpc::string> parts = file->package_parts();
std::vector<std::string> parts = file->package_parts();
for (auto part = parts.rbegin(); part != parts.rend(); part++) {
vars["part"] = *part;
@ -1829,13 +1829,13 @@ grpc::string GetHeaderEpilogue(grpc_generator::File* file,
return output;
}
grpc::string GetSourcePrologue(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetSourcePrologue(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
vars["filename"] = file->filename();
vars["filename_base"] = file->filename_without_ext();
@ -1856,13 +1856,13 @@ grpc::string GetSourcePrologue(grpc_generator::File* file,
return output;
}
grpc::string GetSourceIncludes(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetSourceIncludes(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
static const char* headers_strs[] = {
"functional",
"grpcpp/impl/codegen/async_stream.h",
@ -1878,12 +1878,12 @@ grpc::string GetSourceIncludes(grpc_generator::File* file,
"grpcpp/impl/codegen/server_context.h",
"grpcpp/impl/codegen/service_type.h",
"grpcpp/impl/codegen/sync_stream.h"};
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
std::vector<std::string> headers(headers_strs, array_end(headers_strs));
PrintIncludes(printer.get(), headers, params.use_system_headers,
params.grpc_search_path);
if (!file->package().empty()) {
std::vector<grpc::string> parts = file->package_parts();
std::vector<std::string> parts = file->package_parts();
for (auto part = parts.begin(); part != parts.end(); part++) {
vars["part"] = *part;
@ -1898,15 +1898,15 @@ grpc::string GetSourceIncludes(grpc_generator::File* file,
void PrintSourceClientMethod(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
struct {
grpc::string prefix;
grpc::string start; // bool literal expressed as string
grpc::string method_params; // extra arguments to method
grpc::string create_args; // extra arguments to creator
std::string prefix;
std::string start; // bool literal expressed as string
std::string method_params; // extra arguments to method
std::string create_args; // extra arguments to creator
} async_prefixes[] = {{"Async", "true", ", void* tag", ", tag"},
{"PrepareAsync", "false", "", ", nullptr"}};
if (method->NoStreaming()) {
@ -2122,7 +2122,7 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer,
void PrintSourceServerMethod(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
@ -2181,7 +2181,7 @@ void PrintSourceServerMethod(grpc_generator::Printer* printer,
void PrintSourceService(grpc_generator::Printer* printer,
const grpc_generator::Service* service,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Service"] = service->name();
if (service->method_count() > 0) {
@ -2316,13 +2316,13 @@ void PrintSourceService(grpc_generator::Printer* printer,
}
}
grpc::string GetSourceServices(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetSourceServices(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
// Package string is empty or ends with a dot. It is used to fully qualify
// method names.
vars["Package"] = file->package();
@ -2345,12 +2345,12 @@ grpc::string GetSourceServices(grpc_generator::File* file,
return output;
}
grpc::string GetSourceEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
grpc::string temp;
std::string GetSourceEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
std::string temp;
if (!file->package().empty()) {
std::vector<grpc::string> parts = file->package_parts();
std::vector<std::string> parts = file->package_parts();
for (auto part = parts.begin(); part != parts.end(); part++) {
temp.append("} // namespace ");
@ -2364,13 +2364,13 @@ grpc::string GetSourceEpilogue(grpc_generator::File* file,
}
// TODO(mmukhi): Make sure we need parameters or not.
grpc::string GetMockPrologue(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetMockPrologue(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
vars["filename"] = file->filename();
vars["filename_base"] = file->filename_without_ext();
@ -2387,10 +2387,9 @@ grpc::string GetMockPrologue(grpc_generator::File* file,
printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
if (params.include_import_headers) {
const std::vector<grpc::string> import_names = file->GetImportNames();
const std::vector<std::string> import_names = file->GetImportNames();
for (const auto& import_name : import_names) {
const grpc::string include_name =
ImportInludeFromProtoName(import_name);
const std::string include_name = ImportInludeFromProtoName(import_name);
printer->Print(vars, include_name.c_str());
}
printer->PrintRaw("\n");
@ -2402,23 +2401,23 @@ grpc::string GetMockPrologue(grpc_generator::File* file,
}
// TODO(mmukhi): Add client-stream and completion-queue headers.
grpc::string GetMockIncludes(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetMockIncludes(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
static const char* headers_strs[] = {
"grpcpp/impl/codegen/async_stream.h",
"grpcpp/impl/codegen/sync_stream.h",
};
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
std::vector<std::string> headers(headers_strs, array_end(headers_strs));
PrintIncludes(printer.get(), headers, params.use_system_headers,
params.grpc_search_path);
std::vector<grpc::string> gmock_header;
std::vector<std::string> gmock_header;
if (params.gmock_search_path.empty()) {
gmock_header.push_back("gmock/gmock.h");
PrintIncludes(printer.get(), gmock_header, params.use_system_headers,
@ -2431,7 +2430,7 @@ grpc::string GetMockIncludes(grpc_generator::File* file,
}
if (!file->package().empty()) {
std::vector<grpc::string> parts = file->package_parts();
std::vector<std::string> parts = file->package_parts();
for (auto part = parts.begin(); part != parts.end(); part++) {
vars["part"] = *part;
@ -2446,14 +2445,14 @@ grpc::string GetMockIncludes(grpc_generator::File* file,
void PrintMockClientMethods(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type_name();
(*vars)["Response"] = method->output_type_name();
struct {
grpc::string prefix;
grpc::string method_params; // extra arguments to method
std::string prefix;
std::string method_params; // extra arguments to method
int extra_method_param_count;
} async_prefixes[] = {{"Async", ", void* tag", 1}, {"PrepareAsync", "", 0}};
@ -2530,7 +2529,7 @@ void PrintMockClientMethods(grpc_generator::Printer* printer,
void PrintMockService(grpc_generator::Printer* printer,
const grpc_generator::Service* service,
std::map<grpc::string, grpc::string>* vars) {
std::map<std::string, std::string>* vars) {
(*vars)["Service"] = service->name();
printer->Print(*vars,
@ -2544,13 +2543,13 @@ void PrintMockService(grpc_generator::Printer* printer,
printer->Print("};\n");
}
grpc::string GetMockServices(grpc_generator::File* file,
const Parameters& params) {
grpc::string output;
std::string GetMockServices(grpc_generator::File* file,
const Parameters& params) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto printer = file->CreatePrinter(&output);
std::map<grpc::string, grpc::string> vars;
std::map<std::string, std::string> vars;
// Package string is empty or ends with a dot. It is used to fully qualify
// method names.
vars["Package"] = file->package();
@ -2575,12 +2574,12 @@ grpc::string GetMockServices(grpc_generator::File* file,
return output;
}
grpc::string GetMockEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
grpc::string temp;
std::string GetMockEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
std::string temp;
if (!file->package().empty()) {
std::vector<grpc::string> parts = file->package_parts();
std::vector<std::string> parts = file->package_parts();
for (auto part = parts.begin(); part != parts.end(); part++) {
temp.append("} // namespace ");

@ -24,19 +24,23 @@
// FlatBuffers.
#include <memory>
#include <string>
#include <vector>
#include "src/compiler/config.h"
#include "src/compiler/schema_interface.h"
#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
#ifdef GRPC_CUSTOM_STRING
#warning GRPC_CUSTOM_STRING is no longer supported. Please use std::string.
#endif
namespace grpc {
typedef GRPC_CUSTOM_STRING string;
// Using grpc::string and grpc::to_string is discouraged in favor of
// std::string and std::to_string. This is only for legacy code using
// them explictly.
using std::string; // deprecated
using std::to_string; // deprecated
} // namespace grpc
@ -45,86 +49,86 @@ namespace grpc_cpp_generator {
// Contains all the parameters that are parsed from the command line.
struct Parameters {
// Puts the service into a namespace
grpc::string services_namespace;
std::string services_namespace;
// Use system includes (<>) or local includes ("")
bool use_system_headers;
// Prefix to any grpc include
grpc::string grpc_search_path;
std::string grpc_search_path;
// Generate Google Mock code to facilitate unit testing.
bool generate_mock_code;
// Google Mock search path, when non-empty, local includes will be used.
grpc::string gmock_search_path;
std::string gmock_search_path;
// *EXPERIMENTAL* Additional include files in grpc.pb.h
std::vector<grpc::string> additional_header_includes;
std::vector<std::string> additional_header_includes;
// By default, use "pb.h"
grpc::string message_header_extension;
std::string message_header_extension;
// Whether to include headers corresponding to imports in source file.
bool include_import_headers;
};
// Return the prologue of the generated header file.
grpc::string GetHeaderPrologue(grpc_generator::File* file,
const Parameters& params);
std::string GetHeaderPrologue(grpc_generator::File* file,
const Parameters& params);
// Return the includes needed for generated header file.
grpc::string GetHeaderIncludes(grpc_generator::File* file,
const Parameters& params);
std::string GetHeaderIncludes(grpc_generator::File* file,
const Parameters& params);
// Return the includes needed for generated source file.
grpc::string GetSourceIncludes(grpc_generator::File* file,
const Parameters& params);
std::string GetSourceIncludes(grpc_generator::File* file,
const Parameters& params);
// Return the epilogue of the generated header file.
grpc::string GetHeaderEpilogue(grpc_generator::File* file,
const Parameters& params);
std::string GetHeaderEpilogue(grpc_generator::File* file,
const Parameters& params);
// Return the prologue of the generated source file.
grpc::string GetSourcePrologue(grpc_generator::File* file,
const Parameters& params);
std::string GetSourcePrologue(grpc_generator::File* file,
const Parameters& params);
// Return the services for generated header file.
grpc::string GetHeaderServices(grpc_generator::File* file,
const Parameters& params);
std::string GetHeaderServices(grpc_generator::File* file,
const Parameters& params);
// Return the services for generated source file.
grpc::string GetSourceServices(grpc_generator::File* file,
const Parameters& params);
std::string GetSourceServices(grpc_generator::File* file,
const Parameters& params);
// Return the epilogue of the generated source file.
grpc::string GetSourceEpilogue(grpc_generator::File* file,
const Parameters& params);
std::string GetSourceEpilogue(grpc_generator::File* file,
const Parameters& params);
// Return the prologue of the generated mock file.
grpc::string GetMockPrologue(grpc_generator::File* file,
const Parameters& params);
std::string GetMockPrologue(grpc_generator::File* file,
const Parameters& params);
// Return the includes needed for generated mock file.
grpc::string GetMockIncludes(grpc_generator::File* file,
const Parameters& params);
std::string GetMockIncludes(grpc_generator::File* file,
const Parameters& params);
// Return the services for generated mock file.
grpc::string GetMockServices(grpc_generator::File* file,
const Parameters& params);
std::string GetMockServices(grpc_generator::File* file,
const Parameters& params);
// Return the epilogue of generated mock file.
grpc::string GetMockEpilogue(grpc_generator::File* file,
const Parameters& params);
std::string GetMockEpilogue(grpc_generator::File* file,
const Parameters& params);
// Return the prologue of the generated mock file.
grpc::string GetMockPrologue(grpc_generator::File* file,
const Parameters& params);
std::string GetMockPrologue(grpc_generator::File* file,
const Parameters& params);
// Return the includes needed for generated mock file.
grpc::string GetMockIncludes(grpc_generator::File* file,
const Parameters& params);
std::string GetMockIncludes(grpc_generator::File* file,
const Parameters& params);
// Return the services for generated mock file.
grpc::string GetMockServices(grpc_generator::File* file,
const Parameters& params);
std::string GetMockServices(grpc_generator::File* file,
const Parameters& params);
// Return the epilogue of generated mock file.
grpc::string GetMockEpilogue(grpc_generator::File* file,
const Parameters& params);
std::string GetMockEpilogue(grpc_generator::File* file,
const Parameters& params);
} // namespace grpc_cpp_generator

@ -26,23 +26,23 @@
namespace grpc_cpp_generator {
inline grpc::string DotsToColons(const grpc::string& name) {
inline std::string DotsToColons(const std::string& name) {
return grpc_generator::StringReplace(name, ".", "::");
}
inline grpc::string DotsToUnderscores(const grpc::string& name) {
inline std::string DotsToUnderscores(const std::string& name) {
return grpc_generator::StringReplace(name, ".", "_");
}
inline grpc::string ClassName(const grpc::protobuf::Descriptor* descriptor,
bool qualified) {
inline std::string ClassName(const grpc::protobuf::Descriptor* descriptor,
bool qualified) {
// Find "outer", the descriptor of the top-level message in which
// "descriptor" is embedded.
const grpc::protobuf::Descriptor* outer = descriptor;
while (outer->containing_type() != NULL) outer = outer->containing_type();
const grpc::string& outer_name = outer->full_name();
grpc::string inner_name = descriptor->full_name().substr(outer_name.size());
const std::string& outer_name = outer->full_name();
std::string inner_name = descriptor->full_name().substr(outer_name.size());
if (qualified) {
return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);
@ -54,7 +54,7 @@ inline grpc::string ClassName(const grpc::protobuf::Descriptor* descriptor,
// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetCppComments(const DescriptorType* desc, bool leading) {
inline std::string GetCppComments(const DescriptorType* desc, bool leading) {
return grpc_generator::GetPrefixedComments(desc, leading, "//");
}

@ -39,9 +39,9 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
virtual bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
const std::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const override {
std::string* error) const override {
if (file->options().cc_generic_services()) {
*error =
"cpp grpc proto compiler plugin does not work with generic "
@ -58,11 +58,11 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
ProtoBufFile pbfile(file);
if (!parameter.empty()) {
std::vector<grpc::string> parameters_list =
std::vector<std::string> parameters_list =
grpc_generator::tokenize(parameter, ",");
for (auto parameter_string = parameters_list.begin();
parameter_string != parameters_list.end(); parameter_string++) {
std::vector<grpc::string> param =
std::vector<std::string> param =
grpc_generator::tokenize(*parameter_string, "=");
if (param[0] == "services_namespace") {
generator_parameters.services_namespace = param[1];
@ -72,7 +72,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
} else if (param[1] == "false") {
generator_parameters.use_system_headers = false;
} else {
*error = grpc::string("Invalid parameter: ") + *parameter_string;
*error = std::string("Invalid parameter: ") + *parameter_string;
return false;
}
} else if (param[0] == "grpc_search_path") {
@ -81,7 +81,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
if (param[1] == "true") {
generator_parameters.generate_mock_code = true;
} else if (param[1] != "false") {
*error = grpc::string("Invalid parameter: ") + *parameter_string;
*error = std::string("Invalid parameter: ") + *parameter_string;
return false;
}
} else if (param[0] == "gmock_search_path") {
@ -95,19 +95,19 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
if (param[1] == "true") {
generator_parameters.include_import_headers = true;
} else if (param[1] != "false") {
*error = grpc::string("Invalid parameter: ") + *parameter_string;
*error = std::string("Invalid parameter: ") + *parameter_string;
return false;
}
} else {
*error = grpc::string("Unknown parameter: ") + *parameter_string;
*error = std::string("Unknown parameter: ") + *parameter_string;
return false;
}
}
}
grpc::string file_name = grpc_generator::StripProto(file->name());
std::string file_name = grpc_generator::StripProto(file->name());
grpc::string header_code =
std::string header_code =
grpc_cpp_generator::GetHeaderPrologue(&pbfile, generator_parameters) +
grpc_cpp_generator::GetHeaderIncludes(&pbfile, generator_parameters) +
grpc_cpp_generator::GetHeaderServices(&pbfile, generator_parameters) +
@ -117,7 +117,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
grpc::protobuf::io::CodedOutputStream header_coded_out(header_output.get());
header_coded_out.WriteRaw(header_code.data(), header_code.size());
grpc::string source_code =
std::string source_code =
grpc_cpp_generator::GetSourcePrologue(&pbfile, generator_parameters) +
grpc_cpp_generator::GetSourceIncludes(&pbfile, generator_parameters) +
grpc_cpp_generator::GetSourceServices(&pbfile, generator_parameters) +
@ -130,7 +130,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
if (!generator_parameters.generate_mock_code) {
return true;
}
grpc::string mock_code =
std::string mock_code =
grpc_cpp_generator::GetMockPrologue(&pbfile, generator_parameters) +
grpc_cpp_generator::GetMockIncludes(&pbfile, generator_parameters) +
grpc_cpp_generator::GetMockServices(&pbfile, generator_parameters) +
@ -146,8 +146,8 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
private:
// Insert the given code into the given file at the given insertion point.
void Insert(grpc::protobuf::compiler::GeneratorContext* context,
const grpc::string& filename, const grpc::string& insertion_point,
const grpc::string& code) const {
const std::string& filename, const std::string& insertion_point,
const std::string& code) const {
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
context->OpenForInsert(filename, insertion_point));
grpc::protobuf::io::CodedOutputStream coded_out(output.get());

@ -54,9 +54,9 @@ namespace {
// TODO(jtattermusch): reuse the functionality from google/protobuf.
bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer,
grpc::protobuf::SourceLocation location) {
grpc::string comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;
std::string comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;
if (comments.empty()) {
return false;
}
@ -66,7 +66,7 @@ bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer,
comments = grpc_generator::StringReplace(comments, "&", "&amp;", true);
comments = grpc_generator::StringReplace(comments, "<", "&lt;", true);
std::vector<grpc::string> lines;
std::vector<std::string> lines;
grpc_generator::Split(comments, '\n', &lines);
// TODO: We really should work out which part to put in the summary and which
// to put in the remarks...
@ -81,9 +81,9 @@ bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer,
// Note that we can't remove leading or trailing whitespace as *that's*
// relevant in markdown too.
// (We don't skip "just whitespace" lines, either.)
for (std::vector<grpc::string>::iterator it = lines.begin();
it != lines.end(); ++it) {
grpc::string line = *it;
for (std::vector<std::string>::iterator it = lines.begin(); it != lines.end();
++it) {
std::string line = *it;
if (line.empty()) {
last_was_empty = true;
} else {
@ -706,9 +706,9 @@ void GenerateService(Printer* out, const ServiceDescriptor* service,
} // anonymous namespace
grpc::string GetServices(const FileDescriptor* file, bool generate_client,
bool generate_server, bool internal_access) {
grpc::string output;
std::string GetServices(const FileDescriptor* file, bool generate_client,
bool generate_server, bool internal_access) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@ -729,7 +729,7 @@ grpc::string GetServices(const FileDescriptor* file, bool generate_client,
out.Print("// </auto-generated>\n");
// use C++ style as there are no file-level XML comments in .NET
grpc::string leading_comments = GetCsharpComments(file, true);
std::string leading_comments = GetCsharpComments(file, true);
if (!leading_comments.empty()) {
out.Print("// Original file comments:\n");
out.PrintRaw(leading_comments.c_str());
@ -742,7 +742,7 @@ grpc::string GetServices(const FileDescriptor* file, bool generate_client,
out.Print("using grpc = global::Grpc.Core;\n");
out.Print("\n");
grpc::string file_namespace = GetFileNamespace(file);
std::string file_namespace = GetFileNamespace(file);
if (file_namespace != "") {
out.Print("namespace $namespace$ {\n", "namespace", file_namespace);
out.Indent();

@ -25,9 +25,9 @@
namespace grpc_csharp_generator {
grpc::string GetServices(const grpc::protobuf::FileDescriptor* file,
bool generate_client, bool generate_server,
bool internal_access);
std::string GetServices(const grpc::protobuf::FileDescriptor* file,
bool generate_client, bool generate_server,
bool internal_access);
} // namespace grpc_csharp_generator

@ -25,7 +25,7 @@
namespace grpc_csharp_generator {
inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
grpc::string* file_name_or_error) {
std::string* file_name_or_error) {
*file_name_or_error =
grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs";
return true;
@ -34,8 +34,7 @@ inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetCsharpComments(const DescriptorType* desc,
bool leading) {
inline std::string GetCsharpComments(const DescriptorType* desc, bool leading) {
return grpc_generator::GetPrefixedComments(desc, leading, "//");
}

@ -34,10 +34,10 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
const std::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const override {
std::vector<std::pair<grpc::string, grpc::string> > options;
std::string* error) const override {
std::vector<std::pair<std::string, std::string> > options;
grpc::protobuf::compiler::ParseGeneratorParameter(parameter, &options);
bool generate_client = true;
@ -56,14 +56,14 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
}
grpc::string code = grpc_csharp_generator::GetServices(
std::string code = grpc_csharp_generator::GetServices(
file, generate_client, generate_server, internal_access);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
}
// Get output file name.
grpc::string file_name;
std::string file_name;
if (!grpc_csharp_generator::ServicesFilename(file, &file_name)) {
return false;
}

@ -29,10 +29,10 @@
namespace grpc_generator {
inline bool StripSuffix(grpc::string* filename, const grpc::string& suffix) {
inline bool StripSuffix(std::string* filename, const std::string& suffix) {
if (filename->length() >= suffix.length()) {
size_t suffix_pos = filename->length() - suffix.length();
if (filename->compare(suffix_pos, grpc::string::npos, suffix) == 0) {
if (filename->compare(suffix_pos, std::string::npos, suffix) == 0) {
filename->resize(filename->size() - suffix.size());
return true;
}
@ -41,7 +41,7 @@ inline bool StripSuffix(grpc::string* filename, const grpc::string& suffix) {
return false;
}
inline bool StripPrefix(grpc::string* name, const grpc::string& prefix) {
inline bool StripPrefix(std::string* name, const std::string& prefix) {
if (name->length() >= prefix.length()) {
if (name->substr(0, prefix.size()) == prefix) {
*name = name->substr(prefix.size());
@ -51,20 +51,20 @@ inline bool StripPrefix(grpc::string* name, const grpc::string& prefix) {
return false;
}
inline grpc::string StripProto(grpc::string filename) {
inline std::string StripProto(std::string filename) {
if (!StripSuffix(&filename, ".protodevel")) {
StripSuffix(&filename, ".proto");
}
return filename;
}
inline grpc::string StringReplace(grpc::string str, const grpc::string& from,
const grpc::string& to, bool replace_all) {
inline std::string StringReplace(std::string str, const std::string& from,
const std::string& to, bool replace_all) {
size_t pos = 0;
do {
pos = str.find(from, pos);
if (pos == grpc::string::npos) {
if (pos == std::string::npos) {
break;
}
str.replace(pos, from.length(), to);
@ -74,20 +74,20 @@ inline grpc::string StringReplace(grpc::string str, const grpc::string& from,
return str;
}
inline grpc::string StringReplace(grpc::string str, const grpc::string& from,
const grpc::string& to) {
inline std::string StringReplace(std::string str, const std::string& from,
const std::string& to) {
return StringReplace(str, from, to, true);
}
inline std::vector<grpc::string> tokenize(const grpc::string& input,
const grpc::string& delimiters) {
std::vector<grpc::string> tokens;
inline std::vector<std::string> tokenize(const std::string& input,
const std::string& delimiters) {
std::vector<std::string> tokens;
size_t pos, last_pos = 0;
for (;;) {
bool done = false;
pos = input.find_first_of(delimiters, last_pos);
if (pos == grpc::string::npos) {
if (pos == std::string::npos) {
done = true;
pos = input.length();
}
@ -99,7 +99,7 @@ inline std::vector<grpc::string> tokenize(const grpc::string& input,
}
}
inline grpc::string CapitalizeFirstLetter(grpc::string s) {
inline std::string CapitalizeFirstLetter(std::string s) {
if (s.empty()) {
return s;
}
@ -107,7 +107,7 @@ inline grpc::string CapitalizeFirstLetter(grpc::string s) {
return s;
}
inline grpc::string LowercaseFirstLetter(grpc::string s) {
inline std::string LowercaseFirstLetter(std::string s) {
if (s.empty()) {
return s;
}
@ -115,19 +115,19 @@ inline grpc::string LowercaseFirstLetter(grpc::string s) {
return s;
}
inline grpc::string LowerUnderscoreToUpperCamel(grpc::string str) {
std::vector<grpc::string> tokens = tokenize(str, "_");
grpc::string result = "";
inline std::string LowerUnderscoreToUpperCamel(std::string str) {
std::vector<std::string> tokens = tokenize(str, "_");
std::string result = "";
for (unsigned int i = 0; i < tokens.size(); i++) {
result += CapitalizeFirstLetter(tokens[i]);
}
return result;
}
inline grpc::string FileNameInUpperCamel(
inline std::string FileNameInUpperCamel(
const grpc::protobuf::FileDescriptor* file, bool include_package_path) {
std::vector<grpc::string> tokens = tokenize(StripProto(file->name()), "/");
grpc::string result = "";
std::vector<std::string> tokens = tokenize(StripProto(file->name()), "/");
std::string result = "";
if (include_package_path) {
for (unsigned int i = 0; i < tokens.size() - 1; i++) {
result += tokens[i] + "/";
@ -137,7 +137,7 @@ inline grpc::string FileNameInUpperCamel(
return result;
}
inline grpc::string FileNameInUpperCamel(
inline std::string FileNameInUpperCamel(
const grpc::protobuf::FileDescriptor* file) {
return FileNameInUpperCamel(file, true);
}
@ -166,10 +166,10 @@ inline MethodType GetMethodType(
}
}
inline void Split(const grpc::string& s, char /*delim*/,
std::vector<grpc::string>* append_to) {
inline void Split(const std::string& s, char /*delim*/,
std::vector<std::string>* append_to) {
std::istringstream iss(s);
grpc::string piece;
std::string piece;
while (std::getline(iss, piece)) {
append_to->push_back(piece);
}
@ -184,15 +184,15 @@ enum CommentType {
// Get all the raw comments and append each line without newline to out.
template <typename DescriptorType>
inline void GetComment(const DescriptorType* desc, CommentType type,
std::vector<grpc::string>* out) {
std::vector<std::string>* out) {
grpc::protobuf::SourceLocation location;
if (!desc->GetSourceLocation(&location)) {
return;
}
if (type == COMMENTTYPE_LEADING || type == COMMENTTYPE_TRAILING) {
const grpc::string& comments = type == COMMENTTYPE_LEADING
? location.leading_comments
: location.trailing_comments;
const std::string& comments = type == COMMENTTYPE_LEADING
? location.leading_comments
: location.trailing_comments;
Split(comments, '\n', out);
} else if (type == COMMENTTYPE_LEADING_DETACHED) {
for (unsigned int i = 0; i < location.leading_detached_comments.size();
@ -211,7 +211,7 @@ inline void GetComment(const DescriptorType* desc, CommentType type,
// above syntax line. Return nothing for trailing comments.
template <>
inline void GetComment(const grpc::protobuf::FileDescriptor* desc,
CommentType type, std::vector<grpc::string>* out) {
CommentType type, std::vector<std::string>* out) {
if (type == COMMENTTYPE_TRAILING) {
return;
}
@ -237,11 +237,11 @@ inline void GetComment(const grpc::protobuf::FileDescriptor* desc,
// Add prefix and newline to each comment line and concatenate them together.
// Make sure there is a space after the prefix unless the line is empty.
inline grpc::string GenerateCommentsWithPrefix(
const std::vector<grpc::string>& in, const grpc::string& prefix) {
inline std::string GenerateCommentsWithPrefix(
const std::vector<std::string>& in, const std::string& prefix) {
std::ostringstream oss;
for (auto it = in.begin(); it != in.end(); it++) {
const grpc::string& elem = *it;
const std::string& elem = *it;
if (elem.empty()) {
oss << prefix << "\n";
} else if (elem[0] == ' ') {
@ -254,14 +254,13 @@ inline grpc::string GenerateCommentsWithPrefix(
}
template <typename DescriptorType>
inline grpc::string GetPrefixedComments(const DescriptorType* desc,
bool leading,
const grpc::string& prefix) {
std::vector<grpc::string> out;
inline std::string GetPrefixedComments(const DescriptorType* desc, bool leading,
const std::string& prefix) {
std::vector<std::string> out;
if (leading) {
grpc_generator::GetComment(
desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED, &out);
std::vector<grpc::string> leading;
std::vector<std::string> leading;
grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING,
&leading);
out.insert(out.end(), leading.begin(), leading.end());

@ -37,7 +37,7 @@ 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
grpc::string ModuleAlias(const grpc::string filename) {
std::string ModuleAlias(const std::string filename) {
// This scheme could technically cause problems if a file includes any 2 of:
// foo/bar_baz.proto
// foo_bar_baz.proto
@ -45,7 +45,7 @@ grpc::string ModuleAlias(const grpc::string filename) {
//
// We'll worry about this problem if/when we actually see it. This name isn't
// exposed to users so we can change it later if we need to.
grpc::string basename = grpc_generator::StripProto(filename);
std::string basename = grpc_generator::StripProto(filename);
basename = grpc_generator::StringReplace(basename, "-", "$");
basename = grpc_generator::StringReplace(basename, "/", "_");
basename = grpc_generator::StringReplace(basename, ".", "_");
@ -54,15 +54,15 @@ grpc::string ModuleAlias(const grpc::string filename) {
// Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript
// message file foo/bar/baz.js
grpc::string GetJSMessageFilename(const grpc::string& filename) {
grpc::string name = filename;
std::string GetJSMessageFilename(const std::string& filename) {
std::string name = filename;
return grpc_generator::StripProto(name) + "_pb.js";
}
// Given a filename like foo/bar/baz.proto, returns the root directory
// path ../../
grpc::string GetRootPath(const grpc::string& from_filename,
const grpc::string& to_filename) {
std::string GetRootPath(const std::string& from_filename,
const std::string& to_filename) {
if (to_filename.find("google/protobuf") == 0) {
// Well-known types (.proto files in the google/protobuf directory) are
// assumed to come from the 'google-protobuf' npm package. We may want to
@ -74,7 +74,7 @@ grpc::string GetRootPath(const grpc::string& from_filename,
if (slashes == 0) {
return "./";
}
grpc::string result = "";
std::string result = "";
for (size_t i = 0; i < slashes; i++) {
result += "../";
}
@ -83,16 +83,15 @@ grpc::string GetRootPath(const grpc::string& from_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
grpc::string GetRelativePath(const grpc::string& from_file,
const grpc::string& to_file) {
std::string GetRelativePath(const std::string& from_file,
const std::string& to_file) {
return GetRootPath(from_file, to_file) + 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<grpc::string, const Descriptor*> GetAllMessages(
const FileDescriptor* file) {
map<grpc::string, const Descriptor*> message_types;
map<std::string, const Descriptor*> GetAllMessages(const FileDescriptor* file) {
map<std::string, const Descriptor*> message_types;
for (int service_num = 0; service_num < file->service_count();
service_num++) {
const ServiceDescriptor* service = file->service(service_num);
@ -108,13 +107,13 @@ map<grpc::string, const Descriptor*> GetAllMessages(
return message_types;
}
grpc::string MessageIdentifierName(const grpc::string& name) {
std::string MessageIdentifierName(const std::string& name) {
return grpc_generator::StringReplace(name, ".", "_");
}
grpc::string NodeObjectPath(const Descriptor* descriptor) {
grpc::string module_alias = ModuleAlias(descriptor->file()->name());
grpc::string name = descriptor->full_name();
std::string NodeObjectPath(const Descriptor* descriptor) {
std::string module_alias = ModuleAlias(descriptor->file()->name());
std::string name = descriptor->full_name();
grpc_generator::StripPrefix(&name, descriptor->file()->package() + ".");
return module_alias + "." + name;
}
@ -122,8 +121,8 @@ grpc::string NodeObjectPath(const Descriptor* descriptor) {
// Prints out the message serializer and deserializer functions
void PrintMessageTransformer(const Descriptor* descriptor, Printer* out,
const Parameters& params) {
map<grpc::string, grpc::string> template_vars;
grpc::string full_name = descriptor->full_name();
map<std::string, std::string> template_vars;
std::string full_name = descriptor->full_name();
template_vars["identifier_name"] = MessageIdentifierName(full_name);
template_vars["name"] = full_name;
template_vars["node_name"] = NodeObjectPath(descriptor);
@ -159,7 +158,7 @@ void PrintMessageTransformer(const Descriptor* descriptor, Printer* out,
void PrintMethod(const MethodDescriptor* method, Printer* out) {
const Descriptor* input_type = method->input_type();
const Descriptor* output_type = method->output_type();
map<grpc::string, grpc::string> vars;
map<std::string, std::string> vars;
vars["service_name"] = method->service()->full_name();
vars["name"] = method->name();
vars["input_type"] = NodeObjectPath(input_type);
@ -185,13 +184,13 @@ void PrintMethod(const MethodDescriptor* method, Printer* out) {
// Prints out the service descriptor object
void PrintService(const ServiceDescriptor* service, Printer* out) {
map<grpc::string, grpc::string> template_vars;
map<std::string, std::string> template_vars;
out->Print(GetNodeComments(service, true).c_str());
template_vars["name"] = service->name();
out->Print(template_vars, "var $name$Service = exports.$name$Service = {\n");
out->Indent();
for (int i = 0; i < service->method_count(); i++) {
grpc::string method_name =
std::string method_name =
grpc_generator::LowercaseFirstLetter(service->method(i)->name());
out->Print(GetNodeComments(service->method(i), true).c_str());
out->Print("$method_name$: ", "method_name", method_name);
@ -210,14 +209,14 @@ void PrintService(const ServiceDescriptor* service, Printer* out) {
void PrintImports(const FileDescriptor* file, Printer* out) {
out->Print("var grpc = require('grpc');\n");
if (file->message_type_count() > 0) {
grpc::string file_path =
std::string file_path =
GetRelativePath(file->name(), GetJSMessageFilename(file->name()));
out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias",
ModuleAlias(file->name()), "file_path", file_path);
}
for (int i = 0; i < file->dependency_count(); i++) {
grpc::string file_path = GetRelativePath(
std::string file_path = GetRelativePath(
file->name(), GetJSMessageFilename(file->dependency(i)->name()));
out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias",
ModuleAlias(file->dependency(i)->name()), "file_path",
@ -228,9 +227,8 @@ void PrintImports(const FileDescriptor* file, Printer* out) {
void PrintTransformers(const FileDescriptor* file, Printer* out,
const Parameters& params) {
map<grpc::string, const Descriptor*> messages = GetAllMessages(file);
for (std::map<grpc::string, const Descriptor*>::iterator it =
messages.begin();
map<std::string, const Descriptor*> messages = GetAllMessages(file);
for (std::map<std::string, const Descriptor*>::iterator it = messages.begin();
it != messages.end(); it++) {
PrintMessageTransformer(it->second, out, params);
}
@ -244,9 +242,8 @@ void PrintServices(const FileDescriptor* file, Printer* out) {
}
} // namespace
grpc::string GenerateFile(const FileDescriptor* file,
const Parameters& params) {
grpc::string output;
std::string GenerateFile(const FileDescriptor* file, const Parameters& params) {
std::string output;
{
StringOutputStream output_stream(&output);
Printer out(&output_stream, '$');
@ -256,7 +253,7 @@ grpc::string GenerateFile(const FileDescriptor* file,
}
out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
grpc::string leading_comments = GetNodeComments(file, true);
std::string leading_comments = GetNodeComments(file, true);
if (!leading_comments.empty()) {
out.Print("// Original file comments:\n");
out.PrintRaw(leading_comments.c_str());

@ -29,8 +29,8 @@ struct Parameters {
int minimum_node_version;
};
grpc::string GenerateFile(const grpc::protobuf::FileDescriptor* file,
const Parameters& params);
std::string GenerateFile(const grpc::protobuf::FileDescriptor* file,
const Parameters& params);
} // namespace grpc_node_generator

@ -26,14 +26,14 @@
namespace grpc_node_generator {
inline grpc::string GetJSServiceFilename(const grpc::string& filename) {
inline std::string GetJSServiceFilename(const std::string& filename) {
return grpc_generator::StripProto(filename) + "_grpc_pb.js";
}
// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetNodeComments(const DescriptorType* desc, bool leading) {
inline std::string GetNodeComments(const DescriptorType* desc, bool leading) {
return grpc_generator::GetPrefixedComments(desc, leading, "//");
}

@ -37,36 +37,36 @@ class NodeGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
const std::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const override {
std::string* error) const override {
grpc_node_generator::Parameters generator_parameters;
generator_parameters.minimum_node_version = 4;
if (!parameter.empty()) {
std::vector<grpc::string> parameters_list =
std::vector<std::string> parameters_list =
grpc_generator::tokenize(parameter, ",");
for (auto parameter_string = parameters_list.begin();
parameter_string != parameters_list.end(); parameter_string++) {
std::vector<grpc::string> param =
std::vector<std::string> param =
grpc_generator::tokenize(*parameter_string, "=");
if (param[0] == "minimum_node_version") {
sscanf(param[1].c_str(), "%d",
&generator_parameters.minimum_node_version);
} else {
*error = grpc::string("Unknown parameter: ") + *parameter_string;
*error = std::string("Unknown parameter: ") + *parameter_string;
return false;
}
}
}
grpc::string code = GenerateFile(file, generator_parameters);
std::string code = GenerateFile(file, generator_parameters);
if (code.size() == 0) {
return true;
}
// Get output file name
grpc::string file_name = GetJSServiceFilename(file->name());
std::string file_name = GetJSServiceFilename(file->name());
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
context->Open(file_name));

@ -37,9 +37,9 @@ using ::std::set;
namespace grpc_objective_c_generator {
namespace {
void PrintProtoRpcDeclarationAsPragma(
Printer* printer, const MethodDescriptor* method,
map< ::grpc::string, ::grpc::string> vars) {
void PrintProtoRpcDeclarationAsPragma(Printer* printer,
const MethodDescriptor* method,
map< ::std::string, ::std::string> vars) {
vars["client_stream"] = method->client_streaming() ? "stream " : "";
vars["server_stream"] = method->server_streaming() ? "stream " : "";
@ -51,7 +51,7 @@ void PrintProtoRpcDeclarationAsPragma(
template <typename DescriptorType>
static void PrintAllComments(const DescriptorType* desc, Printer* printer,
bool deprecated = false) {
std::vector<grpc::string> comments;
std::vector<std::string> comments;
grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED,
&comments);
grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING,
@ -65,7 +65,7 @@ static void PrintAllComments(const DescriptorType* desc, Printer* printer,
for (auto it = comments.begin(); it != comments.end(); ++it) {
printer->Print(" * ");
size_t start_pos = it->find_first_not_of(' ');
if (start_pos != grpc::string::npos) {
if (start_pos != std::string::npos) {
printer->PrintRaw(it->c_str() + start_pos);
}
printer->Print("\n");
@ -81,7 +81,7 @@ static void PrintAllComments(const DescriptorType* desc, Printer* printer,
}
void PrintMethodSignature(Printer* printer, const MethodDescriptor* method,
const map< ::grpc::string, ::grpc::string>& vars) {
const map< ::std::string, ::std::string>& vars) {
// Print comment
PrintAllComments(method, printer, true);
@ -106,7 +106,7 @@ void PrintMethodSignature(Printer* printer, const MethodDescriptor* method,
}
void PrintSimpleSignature(Printer* printer, const MethodDescriptor* method,
map< ::grpc::string, ::grpc::string> vars) {
map< ::std::string, ::std::string> vars) {
vars["method_name"] =
grpc_generator::LowercaseFirstLetter(vars["method_name"]);
vars["return_type"] = "void";
@ -114,14 +114,14 @@ void PrintSimpleSignature(Printer* printer, const MethodDescriptor* method,
}
void PrintAdvancedSignature(Printer* printer, const MethodDescriptor* method,
map< ::grpc::string, ::grpc::string> vars) {
map< ::std::string, ::std::string> vars) {
vars["method_name"] = "RPCTo" + vars["method_name"];
vars["return_type"] = "GRPCProtoCall *";
PrintMethodSignature(printer, method, vars);
}
void PrintV2Signature(Printer* printer, const MethodDescriptor* method,
map< ::grpc::string, ::grpc::string> vars) {
map< ::std::string, ::std::string> vars) {
if (method->client_streaming()) {
vars["return_type"] = "GRPCStreamingProtoCall *";
} else {
@ -143,9 +143,9 @@ void PrintV2Signature(Printer* printer, const MethodDescriptor* method,
printer->Print(" callOptions:(GRPCCallOptions *_Nullable)callOptions");
}
inline map< ::grpc::string, ::grpc::string> GetMethodVars(
inline map< ::std::string, ::std::string> GetMethodVars(
const MethodDescriptor* method) {
map< ::grpc::string, ::grpc::string> res;
map< ::std::string, ::std::string> res;
res["method_name"] = method->name();
res["request_type"] = method->input_type()->name();
res["response_type"] = method->output_type()->name();
@ -155,7 +155,7 @@ inline map< ::grpc::string, ::grpc::string> GetMethodVars(
}
void PrintMethodDeclarations(Printer* printer, const MethodDescriptor* method) {
map< ::grpc::string, ::grpc::string> vars = GetMethodVars(method);
map< ::std::string, ::std::string> vars = GetMethodVars(method);
PrintProtoRpcDeclarationAsPragma(printer, method, vars);
@ -167,7 +167,7 @@ void PrintMethodDeclarations(Printer* printer, const MethodDescriptor* method) {
void PrintV2MethodDeclarations(Printer* printer,
const MethodDescriptor* method) {
map< ::grpc::string, ::grpc::string> vars = GetMethodVars(method);
map< ::std::string, ::std::string> vars = GetMethodVars(method);
PrintProtoRpcDeclarationAsPragma(printer, method, vars);
@ -176,7 +176,7 @@ void PrintV2MethodDeclarations(Printer* printer,
}
void PrintSimpleImplementation(Printer* printer, const MethodDescriptor* method,
map< ::grpc::string, ::grpc::string> vars) {
map< ::std::string, ::std::string> vars) {
printer->Print("{\n");
printer->Print(vars, " [[self RPCTo$method_name$With");
if (method->client_streaming()) {
@ -194,7 +194,7 @@ void PrintSimpleImplementation(Printer* printer, const MethodDescriptor* method,
void PrintAdvancedImplementation(Printer* printer,
const MethodDescriptor* method,
map< ::grpc::string, ::grpc::string> vars) {
map< ::std::string, ::std::string> vars) {
printer->Print("{\n");
printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n");
@ -218,7 +218,7 @@ void PrintAdvancedImplementation(Printer* printer,
}
void PrintV2Implementation(Printer* printer, const MethodDescriptor* method,
map< ::grpc::string, ::grpc::string> vars) {
map< ::std::string, ::std::string> vars) {
printer->Print(" {\n");
if (method->client_streaming()) {
printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n");
@ -239,7 +239,7 @@ void PrintV2Implementation(Printer* printer, const MethodDescriptor* method,
void PrintMethodImplementations(Printer* printer,
const MethodDescriptor* method,
const Parameters& generator_params) {
map< ::grpc::string, ::grpc::string> vars = GetMethodVars(method);
map< ::std::string, ::std::string> vars = GetMethodVars(method);
PrintProtoRpcDeclarationAsPragma(printer, method, vars);
@ -259,9 +259,9 @@ void PrintMethodImplementations(Printer* printer,
} // namespace
::grpc::string GetAllMessageClasses(const FileDescriptor* file) {
::grpc::string output;
set< ::grpc::string> classes;
::std::string GetAllMessageClasses(const FileDescriptor* file) {
::std::string output;
set< ::std::string> classes;
for (int i = 0; i < file->service_count(); i++) {
const auto service = file->service(i);
for (int i = 0; i < service->method_count(); i++) {
@ -277,9 +277,9 @@ void PrintMethodImplementations(Printer* printer,
return output;
}
::grpc::string GetProtocol(const ServiceDescriptor* service,
const Parameters& generator_params) {
::grpc::string output;
::std::string GetProtocol(const ServiceDescriptor* service,
const Parameters& generator_params) {
::std::string output;
if (generator_params.no_v1_compatibility) return output;
@ -287,7 +287,7 @@ void PrintMethodImplementations(Printer* printer,
grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$');
map< ::grpc::string, ::grpc::string> vars = {
map< ::std::string, ::std::string> vars = {
{"service_class", ServiceClassName(service)}};
printer.Print(vars,
@ -306,14 +306,14 @@ void PrintMethodImplementations(Printer* printer,
return output;
}
::grpc::string GetV2Protocol(const ServiceDescriptor* service) {
::grpc::string output;
::std::string GetV2Protocol(const ServiceDescriptor* service) {
::std::string output;
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$');
map< ::grpc::string, ::grpc::string> vars = {
map< ::std::string, ::std::string> vars = {
{"service_class", ServiceClassName(service) + "2"}};
printer.Print(vars, "@protocol $service_class$ <NSObject>\n\n");
@ -325,15 +325,15 @@ void PrintMethodImplementations(Printer* printer,
return output;
}
::grpc::string GetInterface(const ServiceDescriptor* service,
const Parameters& generator_params) {
::grpc::string output;
::std::string GetInterface(const ServiceDescriptor* service,
const Parameters& generator_params) {
::std::string output;
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$');
map< ::grpc::string, ::grpc::string> vars = {
map< ::std::string, ::std::string> vars = {
{"service_class", ServiceClassName(service)}};
printer.Print(vars,
@ -368,15 +368,15 @@ void PrintMethodImplementations(Printer* printer,
return output;
}
::grpc::string GetSource(const ServiceDescriptor* service,
const Parameters& generator_params) {
::grpc::string output;
::std::string GetSource(const ServiceDescriptor* service,
const Parameters& generator_params) {
::std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$');
map< ::grpc::string, ::grpc::string> vars = {
map< ::std::string, ::std::string> vars = {
{"service_name", service->name()},
{"service_class", ServiceClassName(service)},
{"package", service->file()->package()}};

@ -28,9 +28,9 @@ struct Parameters {
bool no_v1_compatibility;
};
using ::grpc::string;
using ::grpc::protobuf::FileDescriptor;
using ::grpc::protobuf::ServiceDescriptor;
using ::std::string;
// Returns forward declaration of classes in the generated header file.
string GetAllMessageClasses(const FileDescriptor* file);

@ -27,9 +27,9 @@
namespace grpc_objective_c_generator {
using ::grpc::string;
using ::grpc::protobuf::FileDescriptor;
using ::grpc::protobuf::ServiceDescriptor;
using ::std::string;
inline string MessageHeaderName(const FileDescriptor* file) {
return google::protobuf::compiler::objectivec::FilePath(file) + ".pbobjc.h";
@ -41,53 +41,53 @@ inline string ServiceClassName(const ServiceDescriptor* service) {
return prefix + service->name();
}
inline ::grpc::string LocalImport(const ::grpc::string& import) {
return ::grpc::string("#import \"" + import + "\"\n");
inline ::std::string LocalImport(const ::std::string& import) {
return ::std::string("#import \"" + import + "\"\n");
}
inline ::grpc::string FrameworkImport(const ::grpc::string& import,
const ::grpc::string& framework) {
inline ::std::string FrameworkImport(const ::std::string& import,
const ::std::string& framework) {
// Flattens the directory structure: grab the file name only
std::size_t pos = import.rfind("/");
// If pos is npos, pos + 1 is 0, which gives us the entire string,
// so there's no need to check that
::grpc::string filename = import.substr(pos + 1, import.size() - (pos + 1));
return ::grpc::string("#import <" + framework + "/" + filename + ">\n");
::std::string filename = import.substr(pos + 1, import.size() - (pos + 1));
return ::std::string("#import <" + framework + "/" + filename + ">\n");
}
inline ::grpc::string SystemImport(const ::grpc::string& import) {
return ::grpc::string("#import <" + import + ">\n");
inline ::std::string SystemImport(const ::std::string& import) {
return ::std::string("#import <" + import + ">\n");
}
inline ::grpc::string PreprocConditional(::grpc::string symbol, bool invert) {
inline ::std::string PreprocConditional(::std::string symbol, bool invert) {
return invert ? "!defined(" + symbol + ") || !" + symbol
: "defined(" + symbol + ") && " + symbol;
}
inline ::grpc::string PreprocIf(const ::grpc::string& symbol,
const ::grpc::string& if_true) {
return ::grpc::string("#if " + PreprocConditional(symbol, false) + "\n" +
if_true + "#endif\n");
inline ::std::string PreprocIf(const ::std::string& symbol,
const ::std::string& if_true) {
return ::std::string("#if " + PreprocConditional(symbol, false) + "\n" +
if_true + "#endif\n");
}
inline ::grpc::string PreprocIfNot(const ::grpc::string& symbol,
const ::grpc::string& if_true) {
return ::grpc::string("#if " + PreprocConditional(symbol, true) + "\n" +
if_true + "#endif\n");
inline ::std::string PreprocIfNot(const ::std::string& symbol,
const ::std::string& if_true) {
return ::std::string("#if " + PreprocConditional(symbol, true) + "\n" +
if_true + "#endif\n");
}
inline ::grpc::string PreprocIfElse(const ::grpc::string& symbol,
const ::grpc::string& if_true,
const ::grpc::string& if_false) {
return ::grpc::string("#if " + PreprocConditional(symbol, false) + "\n" +
if_true + "#else\n" + if_false + "#endif\n");
inline ::std::string PreprocIfElse(const ::std::string& symbol,
const ::std::string& if_true,
const ::std::string& if_false) {
return ::std::string("#if " + PreprocConditional(symbol, false) + "\n" +
if_true + "#else\n" + if_false + "#endif\n");
}
inline ::grpc::string PreprocIfNotElse(const ::grpc::string& symbol,
const ::grpc::string& if_true,
const ::grpc::string& if_false) {
return ::grpc::string("#if " + PreprocConditional(symbol, true) + "\n" +
if_true + "#else\n" + if_false + "#endif\n");
inline ::std::string PreprocIfNotElse(const ::std::string& symbol,
const ::std::string& if_true,
const ::std::string& if_false) {
return ::std::string("#if " + PreprocConditional(symbol, true) + "\n" +
if_true + "#else\n" + if_false + "#endif\n");
}
} // namespace grpc_objective_c_generator

@ -37,10 +37,10 @@ using ::grpc_objective_c_generator::SystemImport;
namespace {
inline ::grpc::string ImportProtoHeaders(
inline ::std::string ImportProtoHeaders(
const grpc::protobuf::FileDescriptor* dep, const char* indent,
const ::grpc::string& framework) {
::grpc::string header = grpc_objective_c_generator::MessageHeaderName(dep);
const ::std::string& framework) {
::std::string header = grpc_objective_c_generator::MessageHeaderName(dep);
if (!IsProtobufLibraryBundledProtoFile(dep)) {
if (framework.empty()) {
@ -50,14 +50,14 @@ inline ::grpc::string ImportProtoHeaders(
}
}
::grpc::string base_name = header;
::std::string base_name = header;
grpc_generator::StripPrefix(&base_name, "google/protobuf/");
::grpc::string file_name = "GPB" + base_name;
::std::string file_name = "GPB" + base_name;
// create the import code snippet
::grpc::string framework_header =
::grpc::string(ProtobufLibraryFrameworkName) + "/" + file_name;
::std::string framework_header =
::std::string(ProtobufLibraryFrameworkName) + "/" + file_name;
static const ::grpc::string kFrameworkImportsCondition =
static const ::std::string kFrameworkImportsCondition =
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS";
return PreprocIfElse(kFrameworkImportsCondition,
indent + SystemImport(framework_header),
@ -77,54 +77,54 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
virtual bool Generate(const grpc::protobuf::FileDescriptor* file,
const ::grpc::string& parameter,
const ::std::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
::grpc::string* error) const override {
::std::string* error) const override {
if (file->service_count() == 0) {
// No services. Do nothing.
return true;
}
::grpc::string framework;
std::vector<::grpc::string> params_list =
::std::string framework;
std::vector<::std::string> params_list =
grpc_generator::tokenize(parameter, ",");
for (auto param_str = params_list.begin(); param_str != params_list.end();
++param_str) {
std::vector<::grpc::string> param =
std::vector<::std::string> param =
grpc_generator::tokenize(*param_str, "=");
if (param[0] == "generate_for_named_framework") {
if (param.size() != 2) {
*error =
grpc::string("Format: generate_for_named_framework=<Framework>");
std::string("Format: generate_for_named_framework=<Framework>");
return false;
} else if (param[1].empty()) {
*error = grpc::string(
"Name of framework cannot be empty for parameter: ") +
param[0];
*error =
std::string("Name of framework cannot be empty for parameter: ") +
param[0];
return false;
}
framework = param[1];
}
}
static const ::grpc::string kNonNullBegin = "NS_ASSUME_NONNULL_BEGIN\n";
static const ::grpc::string kNonNullEnd = "NS_ASSUME_NONNULL_END\n";
static const ::grpc::string kProtocolOnly = "GPB_GRPC_PROTOCOL_ONLY";
static const ::grpc::string kForwardDeclare =
static const ::std::string kNonNullBegin = "NS_ASSUME_NONNULL_BEGIN\n";
static const ::std::string kNonNullEnd = "NS_ASSUME_NONNULL_END\n";
static const ::std::string kProtocolOnly = "GPB_GRPC_PROTOCOL_ONLY";
static const ::std::string kForwardDeclare =
"GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO";
::grpc::string file_name =
::std::string file_name =
google::protobuf::compiler::objectivec::FilePath(file);
grpc_objective_c_generator::Parameters generator_params;
generator_params.no_v1_compatibility = false;
if (!parameter.empty()) {
std::vector<grpc::string> parameters_list =
std::vector<std::string> parameters_list =
grpc_generator::tokenize(parameter, ",");
for (auto parameter_string = parameters_list.begin();
parameter_string != parameters_list.end(); parameter_string++) {
std::vector<grpc::string> param =
std::vector<std::string> param =
grpc_generator::tokenize(*parameter_string, "=");
if (param[0] == "no_v1_compatibility") {
generator_params.no_v1_compatibility = true;
@ -133,7 +133,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
// Write out a file header.
::grpc::string file_header =
::std::string file_header =
"// Code generated by gRPC proto compiler. DO NOT EDIT!\n"
"// source: " +
file->name() + "\n\n";
@ -141,14 +141,14 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
{
// Generate .pbrpc.h
::grpc::string imports;
::std::string imports;
if (framework.empty()) {
imports = LocalImport(file_name + ".pbobjc.h");
} else {
imports = FrameworkImport(file_name + ".pbobjc.h", framework);
}
::grpc::string system_imports =
::std::string system_imports =
SystemImport("ProtoRPC/ProtoService.h") +
(generator_params.no_v1_compatibility
? SystemImport("ProtoRPC/ProtoRPC.h")
@ -158,7 +158,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
SystemImport("RxLibrary/GRXWriter.h");
}
::grpc::string forward_declarations =
::std::string forward_declarations =
"@class GRPCUnaryProtoCall;\n"
"@class GRPCStreamingProtoCall;\n"
"@class GRPCCallOptions;\n"
@ -168,29 +168,29 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
forward_declarations += "\n";
::grpc::string class_declarations =
::std::string class_declarations =
grpc_objective_c_generator::GetAllMessageClasses(file);
::grpc::string class_imports;
::std::string class_imports;
for (int i = 0; i < file->dependency_count(); i++) {
class_imports +=
ImportProtoHeaders(file->dependency(i), " ", framework);
}
::grpc::string ng_protocols;
::std::string ng_protocols;
for (int i = 0; i < file->service_count(); i++) {
const grpc::protobuf::ServiceDescriptor* service = file->service(i);
ng_protocols += grpc_objective_c_generator::GetV2Protocol(service);
}
::grpc::string protocols;
::std::string protocols;
for (int i = 0; i < file->service_count(); i++) {
const grpc::protobuf::ServiceDescriptor* service = file->service(i);
protocols +=
grpc_objective_c_generator::GetProtocol(service, generator_params);
}
::grpc::string interfaces;
::std::string interfaces;
for (int i = 0; i < file->service_count(); i++) {
const grpc::protobuf::ServiceDescriptor* service = file->service(i);
interfaces +=
@ -211,7 +211,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
{
// Generate .pbrpc.m
::grpc::string imports;
::std::string imports;
if (framework.empty()) {
imports = LocalImport(file_name + ".pbrpc.h") +
LocalImport(file_name + ".pbobjc.h");
@ -226,12 +226,12 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
imports += SystemImport("RxLibrary/GRXWriter+Immediate.h");
}
::grpc::string class_imports;
::std::string class_imports;
for (int i = 0; i < file->dependency_count(); i++) {
class_imports += ImportProtoHeaders(file->dependency(i), "", framework);
}
::grpc::string definitions;
::std::string definitions;
for (int i = 0; i < file->service_count(); i++) {
const grpc::protobuf::ServiceDescriptor* service = file->service(i);
definitions +=
@ -250,7 +250,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
private:
// Write the given code into the given file.
void Write(grpc::protobuf::compiler::GeneratorContext* context,
const ::grpc::string& filename, const ::grpc::string& code) const {
const ::std::string& filename, const ::std::string& code) const {
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
context->Open(filename));
grpc::protobuf::io::CodedOutputStream coded_out(output.get());

@ -35,8 +35,8 @@ using std::map;
namespace grpc_php_generator {
namespace {
grpc::string ConvertToPhpNamespace(const grpc::string& name) {
std::vector<grpc::string> tokens = grpc_generator::tokenize(name, ".");
std::string ConvertToPhpNamespace(const std::string& name) {
std::vector<std::string> tokens = grpc_generator::tokenize(name, ".");
std::ostringstream oss;
for (unsigned int i = 0; i < tokens.size(); i++) {
oss << (i == 0 ? "" : "\\")
@ -45,7 +45,7 @@ grpc::string ConvertToPhpNamespace(const grpc::string& name) {
return oss.str();
}
grpc::string PackageName(const FileDescriptor* file) {
std::string PackageName(const FileDescriptor* file) {
if (file->options().has_php_namespace()) {
return file->options().php_namespace();
} else {
@ -53,9 +53,9 @@ grpc::string PackageName(const FileDescriptor* file) {
}
}
grpc::string MessageIdentifierName(const grpc::string& name,
const FileDescriptor* file) {
std::vector<grpc::string> tokens = grpc_generator::tokenize(name, ".");
std::string MessageIdentifierName(const std::string& name,
const FileDescriptor* file) {
std::vector<std::string> tokens = grpc_generator::tokenize(name, ".");
std::ostringstream oss;
if (PackageName(file) != "") {
oss << PackageName(file) << "\\";
@ -67,7 +67,7 @@ grpc::string MessageIdentifierName(const grpc::string& name,
void PrintMethod(const MethodDescriptor* method, Printer* out) {
const Descriptor* input_type = method->input_type();
const Descriptor* output_type = method->output_type();
map<grpc::string, grpc::string> vars;
map<std::string, std::string> vars;
vars["service_name"] = method->service()->full_name();
vars["name"] = method->name();
vars["input_type_id"] =
@ -123,8 +123,8 @@ void PrintMethod(const MethodDescriptor* method, Printer* out) {
// Prints out the service descriptor object
void PrintService(const ServiceDescriptor* service,
const grpc::string& class_suffix, Printer* out) {
map<grpc::string, grpc::string> vars;
const std::string& class_suffix, Printer* out) {
map<std::string, std::string> vars;
out->Print("/**\n");
out->Print(GetPHPComments(service, " *").c_str());
out->Print(" */\n");
@ -146,7 +146,7 @@ void PrintService(const ServiceDescriptor* service,
out->Outdent();
out->Print("}\n\n");
for (int i = 0; i < service->method_count(); i++) {
grpc::string method_name =
std::string method_name =
grpc_generator::LowercaseFirstLetter(service->method(i)->name());
PrintMethod(service->method(i), out);
}
@ -156,10 +156,10 @@ void PrintService(const ServiceDescriptor* service,
}
} // namespace
grpc::string GenerateFile(const FileDescriptor* file,
const ServiceDescriptor* service,
const grpc::string& class_suffix) {
grpc::string output;
std::string GenerateFile(const FileDescriptor* file,
const ServiceDescriptor* service,
const std::string& class_suffix) {
std::string output;
{
StringOutputStream output_stream(&output);
Printer out(&output_stream, '$');
@ -167,14 +167,14 @@ grpc::string GenerateFile(const FileDescriptor* file,
out.Print("<?php\n");
out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
grpc::string leading_comments = GetPHPComments(file, "//");
std::string leading_comments = GetPHPComments(file, "//");
if (!leading_comments.empty()) {
out.Print("// Original file comments:\n");
out.PrintRaw(leading_comments.c_str());
}
map<grpc::string, grpc::string> vars;
grpc::string php_namespace = PackageName(file);
map<std::string, std::string> vars;
std::string php_namespace = PackageName(file);
vars["package"] = php_namespace;
out.Print(vars, "namespace $package$;\n\n");

@ -23,9 +23,9 @@
namespace grpc_php_generator {
grpc::string GenerateFile(const grpc::protobuf::FileDescriptor* file,
const grpc::protobuf::ServiceDescriptor* service,
const grpc::string& class_suffix);
std::string GenerateFile(const grpc::protobuf::FileDescriptor* file,
const grpc::protobuf::ServiceDescriptor* service,
const std::string& class_suffix);
} // namespace grpc_php_generator

@ -26,32 +26,32 @@
namespace grpc_php_generator {
inline grpc::string GetPHPServiceClassname(
inline std::string GetPHPServiceClassname(
const grpc::protobuf::ServiceDescriptor* service,
const grpc::string& class_suffix) {
const std::string& class_suffix) {
return service->name() + (class_suffix == "" ? "Client" : class_suffix);
}
// ReplaceAll replaces all instances of search with replace in s.
inline grpc::string ReplaceAll(grpc::string s, const grpc::string& search,
const grpc::string& replace) {
inline std::string ReplaceAll(std::string s, const std::string& search,
const std::string& replace) {
size_t pos = 0;
while ((pos = s.find(search, pos)) != grpc::string::npos) {
while ((pos = s.find(search, pos)) != std::string::npos) {
s.replace(pos, search.length(), replace);
pos += replace.length();
}
return s;
}
inline grpc::string GetPHPServiceFilename(
inline std::string GetPHPServiceFilename(
const grpc::protobuf::FileDescriptor* file,
const grpc::protobuf::ServiceDescriptor* service,
const grpc::string& class_suffix) {
const std::string& class_suffix) {
std::ostringstream oss;
if (file->options().has_php_namespace()) {
oss << ReplaceAll(file->options().php_namespace(), "\\", "/");
} else {
std::vector<grpc::string> tokens =
std::vector<std::string> tokens =
grpc_generator::tokenize(file->package(), ".");
for (unsigned int i = 0; i < tokens.size(); i++) {
oss << (i == 0 ? "" : "/")
@ -65,8 +65,8 @@ inline grpc::string GetPHPServiceFilename(
// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetPHPComments(const DescriptorType* desc,
grpc::string prefix) {
inline std::string GetPHPComments(const DescriptorType* desc,
std::string prefix) {
return ReplaceAll(grpc_generator::GetPrefixedComments(desc, true, prefix),
"*/", "&#42;/");
}

@ -38,17 +38,17 @@ class PHPGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
const std::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const override {
std::string* error) const override {
if (file->service_count() == 0) {
return true;
}
std::vector<std::pair<grpc::string, grpc::string> > options;
std::vector<std::pair<std::string, std::string> > options;
ParseGeneratorParameter(parameter, &options);
grpc::string class_suffix;
std::string class_suffix;
for (size_t i = 0; i < options.size(); ++i) {
if (options[i].first == "class_suffix") {
class_suffix = options[i].second;
@ -59,10 +59,10 @@ class PHPGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
for (int i = 0; i < file->service_count(); i++) {
grpc::string code = GenerateFile(file, file->service(i), class_suffix);
std::string code = GenerateFile(file, file->service(i), class_suffix);
// Get output file name
grpc::string file_name =
std::string file_name =
GetPHPServiceFilename(file, file->service(i), class_suffix);
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(

@ -29,8 +29,8 @@
// Get leading or trailing comments in a string.
template <typename DescriptorType>
inline grpc::string GetCommentsHelper(const DescriptorType* desc, bool leading,
const grpc::string& prefix) {
inline std::string GetCommentsHelper(const DescriptorType* desc, bool leading,
const std::string& prefix) {
return grpc_generator::GetPrefixedComments(desc, leading, prefix);
}
@ -39,36 +39,36 @@ class ProtoBufMethod : public grpc_generator::Method {
ProtoBufMethod(const grpc::protobuf::MethodDescriptor* method)
: method_(method) {}
grpc::string name() const { return method_->name(); }
std::string name() const { return method_->name(); }
grpc::string input_type_name() const {
std::string input_type_name() const {
return grpc_cpp_generator::ClassName(method_->input_type(), true);
}
grpc::string output_type_name() const {
std::string output_type_name() const {
return grpc_cpp_generator::ClassName(method_->output_type(), true);
}
grpc::string get_input_type_name() const {
std::string get_input_type_name() const {
return method_->input_type()->file()->name();
}
grpc::string get_output_type_name() const {
std::string get_output_type_name() const {
return method_->output_type()->file()->name();
}
// TODO(https://github.com/grpc/grpc/issues/18800): Clean this up.
bool get_module_and_message_path_input(
grpc::string* str, grpc::string generator_file_name,
bool generate_in_pb2_grpc, grpc::string import_prefix,
const std::vector<grpc::string>& prefixes_to_filter) const final {
std::string* str, std::string generator_file_name,
bool generate_in_pb2_grpc, std::string import_prefix,
const std::vector<std::string>& prefixes_to_filter) const final {
return grpc_python_generator::GetModuleAndMessagePath(
method_->input_type(), str, generator_file_name, generate_in_pb2_grpc,
import_prefix, prefixes_to_filter);
}
bool get_module_and_message_path_output(
grpc::string* str, grpc::string generator_file_name,
bool generate_in_pb2_grpc, grpc::string import_prefix,
const std::vector<grpc::string>& prefixes_to_filter) const final {
std::string* str, std::string generator_file_name,
bool generate_in_pb2_grpc, std::string import_prefix,
const std::vector<std::string>& prefixes_to_filter) const final {
return grpc_python_generator::GetModuleAndMessagePath(
method_->output_type(), str, generator_file_name, generate_in_pb2_grpc,
import_prefix, prefixes_to_filter);
@ -86,15 +86,15 @@ class ProtoBufMethod : public grpc_generator::Method {
return method_->client_streaming() && method_->server_streaming();
}
grpc::string GetLeadingComments(const grpc::string prefix) const {
std::string GetLeadingComments(const std::string prefix) const {
return GetCommentsHelper(method_, true, prefix);
}
grpc::string GetTrailingComments(const grpc::string prefix) const {
std::string GetTrailingComments(const std::string prefix) const {
return GetCommentsHelper(method_, false, prefix);
}
vector<grpc::string> GetAllComments() const {
vector<std::string> GetAllComments() const {
return grpc_python_generator::get_all_comments(method_);
}
@ -107,7 +107,7 @@ class ProtoBufService : public grpc_generator::Service {
ProtoBufService(const grpc::protobuf::ServiceDescriptor* service)
: service_(service) {}
grpc::string name() const { return service_->name(); }
std::string name() const { return service_->name(); }
int method_count() const { return service_->method_count(); }
std::unique_ptr<const grpc_generator::Method> method(int i) const {
@ -115,15 +115,15 @@ class ProtoBufService : public grpc_generator::Service {
new ProtoBufMethod(service_->method(i)));
}
grpc::string GetLeadingComments(const grpc::string prefix) const {
std::string GetLeadingComments(const std::string prefix) const {
return GetCommentsHelper(service_, true, prefix);
}
grpc::string GetTrailingComments(const grpc::string prefix) const {
std::string GetTrailingComments(const std::string prefix) const {
return GetCommentsHelper(service_, false, prefix);
}
vector<grpc::string> GetAllComments() const {
vector<std::string> GetAllComments() const {
return grpc_python_generator::get_all_comments(service_);
}
@ -133,10 +133,10 @@ class ProtoBufService : public grpc_generator::Service {
class ProtoBufPrinter : public grpc_generator::Printer {
public:
ProtoBufPrinter(grpc::string* str)
ProtoBufPrinter(std::string* str)
: output_stream_(str), printer_(&output_stream_, '$') {}
void Print(const std::map<grpc::string, grpc::string>& vars,
void Print(const std::map<std::string, std::string>& vars,
const char* string_template) {
printer_.Print(vars, string_template);
}
@ -155,17 +155,17 @@ class ProtoBufFile : public grpc_generator::File {
public:
ProtoBufFile(const grpc::protobuf::FileDescriptor* file) : file_(file) {}
grpc::string filename() const { return file_->name(); }
grpc::string filename_without_ext() const {
std::string filename() const { return file_->name(); }
std::string filename_without_ext() const {
return grpc_generator::StripProto(filename());
}
grpc::string package() const { return file_->package(); }
std::vector<grpc::string> package_parts() const {
std::string package() const { return file_->package(); }
std::vector<std::string> package_parts() const {
return grpc_generator::tokenize(package(), ".");
}
grpc::string additional_headers() const { return ""; }
std::string additional_headers() const { return ""; }
int service_count() const { return file_->service_count(); }
std::unique_ptr<const grpc_generator::Service> service(int i) const {
@ -174,24 +174,24 @@ class ProtoBufFile : public grpc_generator::File {
}
std::unique_ptr<grpc_generator::Printer> CreatePrinter(
grpc::string* str) const {
std::string* str) const {
return std::unique_ptr<grpc_generator::Printer>(new ProtoBufPrinter(str));
}
grpc::string GetLeadingComments(const grpc::string prefix) const {
std::string GetLeadingComments(const std::string prefix) const {
return GetCommentsHelper(file_, true, prefix);
}
grpc::string GetTrailingComments(const grpc::string prefix) const {
std::string GetTrailingComments(const std::string prefix) const {
return GetCommentsHelper(file_, false, prefix);
}
vector<grpc::string> GetAllComments() const {
vector<std::string> GetAllComments() const {
return grpc_python_generator::get_all_comments(file_);
}
vector<grpc::string> GetImportNames() const {
vector<grpc::string> proto_names;
vector<std::string> GetImportNames() const {
vector<std::string> proto_names;
for (int i = 0; i < file_->dependency_count(); ++i) {
const auto& dep = *file_->dependency(i);
proto_names.push_back(dep.name());

@ -51,13 +51,13 @@ using std::vector;
namespace grpc_python_generator {
grpc::string generator_file_name;
std::string generator_file_name;
namespace {
typedef map<grpc::string, grpc::string> StringMap;
typedef vector<grpc::string> StringVector;
typedef tuple<grpc::string, grpc::string> StringPair;
typedef map<std::string, std::string> StringMap;
typedef vector<std::string> StringVector;
typedef tuple<std::string, std::string> StringPair;
typedef set<StringPair> StringPairSet;
// Provides RAII indentation handling. Use as:
@ -107,7 +107,7 @@ void PrivateGenerator::PrintAllComments(StringVector comments,
for (StringVector::iterator it = comments.begin(); it != comments.end();
++it) {
size_t start_pos = it->find_first_not_of(' ');
if (start_pos != grpc::string::npos) {
if (start_pos != std::string::npos) {
out->PrintRaw(it->c_str() + start_pos);
}
out->Print("\n");
@ -134,7 +134,7 @@ bool PrivateGenerator::PrintBetaServicer(const grpc_generator::Service* service,
PrintAllComments(service_comments, out);
for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
grpc::string arg_name =
std::string arg_name =
method->ClientStreaming() ? "request_iterator" : "request";
StringMap method_dict;
method_dict["Method"] = method->name();
@ -170,7 +170,7 @@ bool PrivateGenerator::PrintBetaStub(const grpc_generator::Service* service,
PrintAllComments(service_comments, out);
for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
grpc::string arg_name =
std::string arg_name =
method->ClientStreaming() ? "request_iterator" : "request";
StringMap method_dict;
method_dict["Method"] = method->name();
@ -193,7 +193,7 @@ bool PrivateGenerator::PrintBetaStub(const grpc_generator::Service* service,
}
bool PrivateGenerator::PrintBetaServerFactory(
const grpc::string& package_qualified_service_name,
const std::string& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap service_dict;
service_dict["Service"] = service->name();
@ -214,18 +214,18 @@ bool PrivateGenerator::PrintBetaServerFactory(
StringMap output_message_modules_and_classes;
for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
const grpc::string method_implementation_constructor =
grpc::string(method->ClientStreaming() ? "stream_" : "unary_") +
grpc::string(method->ServerStreaming() ? "stream_" : "unary_") +
const std::string method_implementation_constructor =
std::string(method->ClientStreaming() ? "stream_" : "unary_") +
std::string(method->ServerStreaming() ? "stream_" : "unary_") +
"inline";
grpc::string input_message_module_and_class;
std::string input_message_module_and_class;
if (!method->get_module_and_message_path_input(
&input_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
return false;
}
grpc::string output_message_module_and_class;
std::string output_message_module_and_class;
if (!method->get_module_and_message_path_output(
&output_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
@ -280,7 +280,7 @@ bool PrivateGenerator::PrintBetaServerFactory(
method_dict["Method"] = name_and_implementation_constructor->first;
method_dict["Constructor"] = name_and_implementation_constructor->second;
IndentScope raii_descriptions_indent(out);
const grpc::string method_name =
const std::string method_name =
name_and_implementation_constructor->first;
out->Print(method_dict,
"(\'$PackageQualifiedServiceName$\', \'$Method$\'): "
@ -302,7 +302,7 @@ bool PrivateGenerator::PrintBetaServerFactory(
}
bool PrivateGenerator::PrintBetaStubFactory(
const grpc::string& package_qualified_service_name,
const std::string& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap dict;
dict["Service"] = service->name();
@ -323,17 +323,17 @@ bool PrivateGenerator::PrintBetaStubFactory(
StringMap output_message_modules_and_classes;
for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
const grpc::string method_cardinality =
grpc::string(method->ClientStreaming() ? "STREAM" : "UNARY") + "_" +
grpc::string(method->ServerStreaming() ? "STREAM" : "UNARY");
grpc::string input_message_module_and_class;
const std::string method_cardinality =
std::string(method->ClientStreaming() ? "STREAM" : "UNARY") + "_" +
std::string(method->ServerStreaming() ? "STREAM" : "UNARY");
std::string input_message_module_and_class;
if (!method->get_module_and_message_path_input(
&input_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
return false;
}
grpc::string output_message_module_and_class;
std::string output_message_module_and_class;
if (!method->get_module_and_message_path_output(
&output_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
@ -406,7 +406,7 @@ bool PrivateGenerator::PrintBetaStubFactory(
}
bool PrivateGenerator::PrintStub(
const grpc::string& package_qualified_service_name,
const std::string& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap dict;
dict["Service"] = service->name();
@ -430,17 +430,17 @@ bool PrivateGenerator::PrintStub(
out->Print("\"\"\"\n");
for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
grpc::string multi_callable_constructor =
grpc::string(method->ClientStreaming() ? "stream" : "unary") + "_" +
grpc::string(method->ServerStreaming() ? "stream" : "unary");
grpc::string request_module_and_class;
std::string multi_callable_constructor =
std::string(method->ClientStreaming() ? "stream" : "unary") + "_" +
std::string(method->ServerStreaming() ? "stream" : "unary");
std::string request_module_and_class;
if (!method->get_module_and_message_path_input(
&request_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
return false;
}
grpc::string response_module_and_class;
std::string response_module_and_class;
if (!method->get_module_and_message_path_output(
&response_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
@ -486,7 +486,7 @@ bool PrivateGenerator::PrintServicer(const grpc_generator::Service* service,
PrintAllComments(service_comments, out);
for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
grpc::string arg_name =
std::string arg_name =
method->ClientStreaming() ? "request_iterator" : "request";
StringMap method_dict;
method_dict["Method"] = method->name();
@ -507,7 +507,7 @@ bool PrivateGenerator::PrintServicer(const grpc_generator::Service* service,
}
bool PrivateGenerator::PrintAddServicerToServer(
const grpc::string& package_qualified_service_name,
const std::string& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap service_dict;
service_dict["Service"] = service->name();
@ -522,18 +522,18 @@ bool PrivateGenerator::PrintAddServicerToServer(
IndentScope raii_dict_second_indent(out);
for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
grpc::string method_handler_constructor =
grpc::string(method->ClientStreaming() ? "stream" : "unary") + "_" +
grpc::string(method->ServerStreaming() ? "stream" : "unary") +
std::string method_handler_constructor =
std::string(method->ClientStreaming() ? "stream" : "unary") + "_" +
std::string(method->ServerStreaming() ? "stream" : "unary") +
"_rpc_method_handler";
grpc::string request_module_and_class;
std::string request_module_and_class;
if (!method->get_module_and_message_path_input(
&request_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
return false;
}
grpc::string response_module_and_class;
std::string response_module_and_class;
if (!method->get_module_and_message_path_output(
&response_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
@ -583,7 +583,7 @@ bool PrivateGenerator::PrintAddServicerToServer(
* should never be instantiated.
*/
bool PrivateGenerator::PrintServiceClass(
const grpc::string& package_qualified_service_name,
const std::string& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap dict;
dict["Service"] = service->name();
@ -596,14 +596,14 @@ bool PrivateGenerator::PrintServiceClass(
PrintAllComments(service_comments, out);
for (int i = 0; i < service->method_count(); ++i) {
const auto& method = service->method(i);
grpc::string request_module_and_class;
std::string request_module_and_class;
if (!method->get_module_and_message_path_input(
&request_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
return false;
}
grpc::string response_module_and_class;
std::string response_module_and_class;
if (!method->get_module_and_message_path_output(
&response_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
@ -615,7 +615,7 @@ bool PrivateGenerator::PrintServiceClass(
method_dict["Method"] = method->name();
out->Print("@staticmethod\n");
out->Print(method_dict, "def $Method$(");
grpc::string request_parameter(
std::string request_parameter(
method->ClientStreaming() ? "request_iterator" : "request");
StringMap args_dict;
args_dict["RequestParameter"] = request_parameter;
@ -635,9 +635,9 @@ bool PrivateGenerator::PrintServiceClass(
}
{
IndentScope method_indent(out);
grpc::string arity_method_name =
grpc::string(method->ClientStreaming() ? "stream" : "unary") + "_" +
grpc::string(method->ServerStreaming() ? "stream" : "unary");
std::string arity_method_name =
std::string(method->ClientStreaming() ? "stream" : "unary") + "_" +
std::string(method->ServerStreaming() ? "stream" : "unary");
args_dict["ArityMethodName"] = arity_method_name;
args_dict["PackageQualifiedService"] = package_qualified_service_name;
args_dict["Method"] = method->name();
@ -690,21 +690,21 @@ bool PrivateGenerator::PrintPreamble(grpc_generator::Printer* out) {
for (int j = 0; j < service->method_count(); ++j) {
auto method = service.get()->method(j);
grpc::string input_type_file_name = method->get_input_type_name();
grpc::string input_module_name =
std::string input_type_file_name = method->get_input_type_name();
std::string input_module_name =
ModuleName(input_type_file_name, config.import_prefix,
config.prefixes_to_filter);
grpc::string input_module_alias =
std::string input_module_alias =
ModuleAlias(input_type_file_name, config.import_prefix,
config.prefixes_to_filter);
imports_set.insert(
std::make_tuple(input_module_name, input_module_alias));
grpc::string output_type_file_name = method->get_output_type_name();
grpc::string output_module_name =
std::string output_type_file_name = method->get_output_type_name();
std::string output_module_name =
ModuleName(output_type_file_name, config.import_prefix,
config.prefixes_to_filter);
grpc::string output_module_alias =
std::string output_module_alias =
ModuleAlias(output_type_file_name, config.import_prefix,
config.prefixes_to_filter);
imports_set.insert(
@ -717,7 +717,7 @@ bool PrivateGenerator::PrintPreamble(grpc_generator::Printer* out) {
auto module_name = std::get<0>(*it);
var["ModuleAlias"] = std::get<1>(*it);
const size_t last_dot_pos = module_name.rfind('.');
if (last_dot_pos == grpc::string::npos) {
if (last_dot_pos == std::string::npos) {
var["ImportStatement"] = "import " + module_name;
} else {
var["ImportStatement"] = "from " + module_name.substr(0, last_dot_pos) +
@ -731,13 +731,13 @@ bool PrivateGenerator::PrintPreamble(grpc_generator::Printer* out) {
}
bool PrivateGenerator::PrintGAServices(grpc_generator::Printer* out) {
grpc::string package = file->package();
std::string package = file->package();
if (!package.empty()) {
package = package.append(".");
}
for (int i = 0; i < file->service_count(); ++i) {
auto service = file->service(i);
grpc::string package_qualified_service_name = package + service->name();
std::string package_qualified_service_name = package + service->name();
if (!(PrintStub(package_qualified_service_name, service.get(), out) &&
PrintServicer(service.get(), out) &&
PrintAddServicerToServer(package_qualified_service_name,
@ -751,13 +751,13 @@ bool PrivateGenerator::PrintGAServices(grpc_generator::Printer* out) {
}
bool PrivateGenerator::PrintBetaServices(grpc_generator::Printer* out) {
grpc::string package = file->package();
std::string package = file->package();
if (!package.empty()) {
package = package.append(".");
}
for (int i = 0; i < file->service_count(); ++i) {
auto service = file->service(i);
grpc::string package_qualified_service_name = package + service->name();
std::string package_qualified_service_name = package + service->name();
if (!(PrintBetaServicer(service.get(), out) &&
PrintBetaStub(service.get(), out) &&
PrintBetaServerFactory(package_qualified_service_name, service.get(),
@ -770,8 +770,8 @@ bool PrivateGenerator::PrintBetaServices(grpc_generator::Printer* out) {
return true;
}
pair<bool, grpc::string> PrivateGenerator::GetGrpcServices() {
grpc::string output;
pair<bool, std::string> PrivateGenerator::GetGrpcServices() {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
auto out = file->CreatePrinter(&output);
@ -830,11 +830,11 @@ PythonGrpcGenerator::PythonGrpcGenerator(const GeneratorConfiguration& config)
PythonGrpcGenerator::~PythonGrpcGenerator() {}
static bool GenerateGrpc(GeneratorContext* context, PrivateGenerator& generator,
grpc::string file_name, bool generate_in_pb2_grpc) {
std::string file_name, bool generate_in_pb2_grpc) {
bool success;
std::unique_ptr<ZeroCopyOutputStream> output;
std::unique_ptr<CodedOutputStream> coded_output;
grpc::string grpc_code;
std::string grpc_code;
if (generate_in_pb2_grpc) {
output.reset(context->Open(file_name));
@ -855,11 +855,11 @@ static bool GenerateGrpc(GeneratorContext* context, PrivateGenerator& generator,
}
}
static bool ParseParameters(const grpc::string& parameter,
grpc::string* grpc_version,
std::vector<grpc::string>* strip_prefixes,
grpc::string* error) {
std::vector<grpc::string> comma_delimited_parameters;
static bool ParseParameters(const std::string& parameter,
std::string* grpc_version,
std::vector<std::string>* strip_prefixes,
std::string* error) {
std::vector<std::string> comma_delimited_parameters;
grpc_python_generator::Split(parameter, ',', &comma_delimited_parameters);
if (comma_delimited_parameters.size() == 1 &&
comma_delimited_parameters[0].empty()) {
@ -883,16 +883,16 @@ uint64_t PythonGrpcGenerator::GetSupportedFeatures() const {
}
bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
const grpc::string& parameter,
const std::string& parameter,
GeneratorContext* context,
grpc::string* error) const {
std::string* error) const {
// Get output file name.
grpc::string pb2_file_name;
grpc::string pb2_grpc_file_name;
std::string pb2_file_name;
std::string pb2_grpc_file_name;
static const int proto_suffix_length = strlen(".proto");
if (file->name().size() > static_cast<size_t>(proto_suffix_length) &&
file->name().find_last_of(".proto") == file->name().size() - 1) {
grpc::string base =
std::string base =
file->name().substr(0, file->name().size() - proto_suffix_length);
std::replace(base.begin(), base.end(), '-', '_');
pb2_file_name = base + "_pb2.py";
@ -904,7 +904,7 @@ bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
generator_file_name = file->name();
ProtoBufFile pbfile(file);
grpc::string grpc_version;
std::string grpc_version;
GeneratorConfiguration extended_config(config_);
bool success = ParseParameters(parameter, &grpc_version,
&(extended_config.prefixes_to_filter), error);

@ -31,12 +31,12 @@ namespace grpc_python_generator {
// that may be used internally at Google.
struct GeneratorConfiguration {
GeneratorConfiguration();
grpc::string grpc_package_root;
std::string grpc_package_root;
// TODO(https://github.com/grpc/grpc/issues/8622): Drop this.
grpc::string beta_package_root;
std::string beta_package_root;
// TODO(https://github.com/google/protobuf/issues/888): Drop this.
grpc::string import_prefix;
std::vector<grpc::string> prefixes_to_filter;
std::string import_prefix;
std::vector<std::string> prefixes_to_filter;
};
class PythonGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
@ -47,9 +47,9 @@ class PythonGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
uint64_t GetSupportedFeatures() const override;
bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
const std::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const override;
std::string* error) const override;
private:
GeneratorConfiguration config_;

@ -47,11 +47,11 @@ namespace grpc_python_generator {
namespace {
typedef vector<const Descriptor*> DescriptorVector;
typedef vector<grpc::string> StringVector;
typedef vector<std::string> StringVector;
static grpc::string StripModulePrefixes(
const grpc::string& raw_module_name,
const std::vector<grpc::string>& prefixes_to_filter) {
static std::string StripModulePrefixes(
const std::string& raw_module_name,
const std::vector<std::string>& prefixes_to_filter) {
for (const auto& prefix : prefixes_to_filter) {
if (raw_module_name.rfind(prefix, 0) == 0) {
return raw_module_name.substr(prefix.size(),
@ -64,10 +64,10 @@ static grpc::string StripModulePrefixes(
// TODO(https://github.com/google/protobuf/issues/888):
// Export `ModuleName` from protobuf's
// `src/google/protobuf/compiler/python/python_generator.cc` file.
grpc::string ModuleName(const grpc::string& filename,
const grpc::string& import_prefix,
const std::vector<grpc::string>& prefixes_to_filter) {
grpc::string basename = StripProto(filename);
std::string ModuleName(const std::string& filename,
const std::string& import_prefix,
const std::vector<std::string>& prefixes_to_filter) {
std::string basename = StripProto(filename);
basename = StringReplace(basename, "-", "_");
basename = StringReplace(basename, "/", ".");
return StripModulePrefixes(import_prefix + basename + "_pb2",
@ -77,10 +77,10 @@ grpc::string ModuleName(const grpc::string& filename,
// TODO(https://github.com/google/protobuf/issues/888):
// Export `ModuleAlias` from protobuf's
// `src/google/protobuf/compiler/python/python_generator.cc` file.
grpc::string ModuleAlias(const grpc::string& filename,
const grpc::string& import_prefix,
const std::vector<grpc::string>& prefixes_to_filter) {
grpc::string module_name =
std::string ModuleAlias(const std::string& filename,
const std::string& import_prefix,
const std::vector<std::string>& prefixes_to_filter) {
std::string module_name =
ModuleName(filename, import_prefix, prefixes_to_filter);
// We can't have dots in the module name, so we replace each with _dot_.
// But that could lead to a collision between a.b and a_dot_b, so we also
@ -91,29 +91,29 @@ grpc::string ModuleAlias(const grpc::string& filename,
}
bool GetModuleAndMessagePath(
const Descriptor* type, grpc::string* out, grpc::string generator_file_name,
bool generate_in_pb2_grpc, grpc::string& import_prefix,
const std::vector<grpc::string>& prefixes_to_filter) {
const Descriptor* type, std::string* out, std::string generator_file_name,
bool generate_in_pb2_grpc, std::string& import_prefix,
const std::vector<std::string>& prefixes_to_filter) {
const Descriptor* path_elem_type = type;
DescriptorVector message_path;
do {
message_path.push_back(path_elem_type);
path_elem_type = path_elem_type->containing_type();
} while (path_elem_type); // implicit nullptr comparison; don't be explicit
grpc::string file_name = type->file()->name();
std::string file_name = type->file()->name();
static const int proto_suffix_length = strlen(".proto");
if (!(file_name.size() > static_cast<size_t>(proto_suffix_length) &&
file_name.find_last_of(".proto") == file_name.size() - 1)) {
return false;
}
grpc::string module;
std::string module;
if (generator_file_name != file_name || generate_in_pb2_grpc) {
module = ModuleAlias(file_name, import_prefix, prefixes_to_filter) + ".";
} else {
module = "";
}
grpc::string message_type;
std::string message_type;
for (DescriptorVector::reverse_iterator path_iter = message_path.rbegin();
path_iter != message_path.rend(); ++path_iter) {
message_type += (*path_iter)->name() + ".";
@ -136,8 +136,8 @@ StringVector get_all_comments(const DescriptorType* descriptor) {
return comments;
}
inline void Split(const grpc::string& s, char delim,
std::vector<grpc::string>* append_to) {
inline void Split(const std::string& s, char delim,
std::vector<std::string>* append_to) {
auto current = s.begin();
while (current <= s.end()) {
auto next = std::find(current, s.end(), delim);

@ -42,7 +42,7 @@ struct PrivateGenerator {
PrivateGenerator(const GeneratorConfiguration& config,
const grpc_generator::File* file);
std::pair<bool, grpc::string> GetGrpcServices();
std::pair<bool, std::string> GetGrpcServices();
private:
bool PrintPreamble(grpc_generator::Printer* out);
@ -51,32 +51,32 @@ struct PrivateGenerator {
bool PrintBetaServices(grpc_generator::Printer* out);
bool PrintAddServicerToServer(
const grpc::string& package_qualified_service_name,
const std::string& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out);
bool PrintServicer(const grpc_generator::Service* service,
grpc_generator::Printer* out);
bool PrintStub(const grpc::string& package_qualified_service_name,
bool PrintStub(const std::string& package_qualified_service_name,
const grpc_generator::Service* service,
grpc_generator::Printer* out);
bool PrintServiceClass(const grpc::string& package_qualified_service_name,
bool PrintServiceClass(const std::string& package_qualified_service_name,
const grpc_generator::Service* service,
grpc_generator::Printer* out);
bool PrintBetaServicer(const grpc_generator::Service* service,
grpc_generator::Printer* out);
bool PrintBetaServerFactory(
const grpc::string& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out);
bool PrintBetaServerFactory(const std::string& package_qualified_service_name,
const grpc_generator::Service* service,
grpc_generator::Printer* out);
bool PrintBetaStub(const grpc_generator::Service* service,
grpc_generator::Printer* out);
bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name,
bool PrintBetaStubFactory(const std::string& package_qualified_service_name,
const grpc_generator::Service* service,
grpc_generator::Printer* out);
// Get all comments (leading, leading_detached, trailing) and print them as a
// docstring. Any leading space of a line will be removed, but the line
// wrapping will not be changed.
void PrintAllComments(std::vector<grpc::string> comments,
void PrintAllComments(std::vector<std::string> comments,
grpc_generator::Printer* out);
};

@ -38,17 +38,17 @@ namespace grpc_ruby_generator {
namespace {
// Prints out the method using the ruby gRPC DSL.
void PrintMethod(const MethodDescriptor* method, const grpc::string& package,
void PrintMethod(const MethodDescriptor* method, const std::string& package,
Printer* out) {
grpc::string input_type = RubyTypeOf(method->input_type(), package);
std::string input_type = RubyTypeOf(method->input_type(), package);
if (method->client_streaming()) {
input_type = "stream(" + input_type + ")";
}
grpc::string output_type = RubyTypeOf(method->output_type(), package);
std::string output_type = RubyTypeOf(method->output_type(), package);
if (method->server_streaming()) {
output_type = "stream(" + output_type + ")";
}
std::map<grpc::string, grpc::string> method_vars = ListToDict({
std::map<std::string, std::string> method_vars = ListToDict({
"mth.name",
method->name(),
"input.type",
@ -62,14 +62,14 @@ void PrintMethod(const MethodDescriptor* method, const grpc::string& package,
}
// Prints out the service using the ruby gRPC DSL.
void PrintService(const ServiceDescriptor* service, const grpc::string& package,
void PrintService(const ServiceDescriptor* service, const std::string& package,
Printer* out) {
if (service->method_count() == 0) {
return;
}
// Begin the service module
std::map<grpc::string, grpc::string> module_vars = ListToDict({
std::map<std::string, std::string> module_vars = ListToDict({
"module.name",
Modularize(service->name()),
});
@ -86,7 +86,7 @@ void PrintService(const ServiceDescriptor* service, const grpc::string& package,
out->Print("\n");
out->Print("self.marshal_class_method = :encode\n");
out->Print("self.unmarshal_class_method = :decode\n");
std::map<grpc::string, grpc::string> pkg_vars =
std::map<std::string, std::string> pkg_vars =
ListToDict({"service_full_name", service->full_name()});
out->Print(pkg_vars, "self.service_name = '$service_full_name$'\n");
out->Print("\n");
@ -122,12 +122,12 @@ char ToUpper(char ch) { return IsLower(ch) ? (ch - 'a' + 'A') : ch; }
// names must be PascalCased.
//
// foo_bar_baz -> FooBarBaz
grpc::string PackageToModule(const grpc::string& name) {
std::string PackageToModule(const std::string& name) {
bool next_upper = true;
grpc::string result;
std::string result;
result.reserve(name.size());
for (grpc::string::size_type i = 0; i < name.size(); i++) {
for (std::string::size_type i = 0; i < name.size(); i++) {
if (name[i] == '_') {
next_upper = true;
} else {
@ -144,8 +144,8 @@ grpc::string PackageToModule(const grpc::string& name) {
}
// end copying of protoc generator for ruby code
grpc::string GetServices(const FileDescriptor* file) {
grpc::string output;
std::string GetServices(const FileDescriptor* file) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@ -161,7 +161,7 @@ grpc::string GetServices(const FileDescriptor* file) {
std::string package_name = RubyPackage(file);
// Write out a file header.
std::map<grpc::string, grpc::string> header_comment_vars = ListToDict({
std::map<std::string, std::string> header_comment_vars = ListToDict({
"file.name",
file->name(),
"file.package",
@ -171,7 +171,7 @@ grpc::string GetServices(const FileDescriptor* file) {
out.Print(header_comment_vars,
"# Source: $file.name$ for package '$file.package$'\n");
grpc::string leading_comments = GetRubyComments(file, true);
std::string leading_comments = GetRubyComments(file, true);
if (!leading_comments.empty()) {
out.Print("# Original file comments:\n");
out.PrintRaw(leading_comments.c_str());
@ -182,7 +182,7 @@ grpc::string GetServices(const FileDescriptor* file) {
// Write out require statemment to import the separately generated file
// that defines the messages used by the service. This is generated by the
// main ruby plugin.
std::map<grpc::string, grpc::string> dep_vars = ListToDict({
std::map<std::string, std::string> dep_vars = ListToDict({
"dep.name",
MessagesRequireName(file),
});
@ -190,9 +190,9 @@ grpc::string GetServices(const FileDescriptor* file) {
// Write out services within the modules
out.Print("\n");
std::vector<grpc::string> modules = Split(package_name, '.');
std::vector<std::string> modules = Split(package_name, '.');
for (size_t i = 0; i < modules.size(); ++i) {
std::map<grpc::string, grpc::string> module_vars = ListToDict({
std::map<std::string, std::string> module_vars = ListToDict({
"module.name",
PackageToModule(modules[i]),
});

@ -23,7 +23,7 @@
namespace grpc_ruby_generator {
grpc::string GetServices(const grpc::protobuf::FileDescriptor* file);
std::string GetServices(const grpc::protobuf::FileDescriptor* file);
} // namespace grpc_ruby_generator

@ -26,7 +26,7 @@
namespace grpc_ruby_generator {
inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
grpc::string* file_name_or_error) {
std::string* file_name_or_error) {
// Get output file name.
static const unsigned proto_suffix_length = 6; // length of ".proto"
if (file->name().size() > proto_suffix_length &&
@ -41,7 +41,7 @@ inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
}
}
inline grpc::string MessagesRequireName(
inline std::string MessagesRequireName(
const grpc::protobuf::FileDescriptor* file) {
return Replace(file->name(), ".proto", "_pb");
}
@ -49,7 +49,7 @@ inline grpc::string MessagesRequireName(
// Get leading or trailing comments in a string. Comment lines start with "# ".
// Leading detached comments are put in front of leading comments.
template <typename DescriptorType>
inline grpc::string GetRubyComments(const DescriptorType* desc, bool leading) {
inline std::string GetRubyComments(const DescriptorType* desc, bool leading) {
return grpc_generator::GetPrefixedComments(desc, leading, "#");
}

@ -35,17 +35,17 @@ namespace grpc_ruby_generator {
// Converts an initializer list of the form { key0, value0, key1, value1, ... }
// into a map of key* to value*. Is merely a readability helper for later code.
inline std::map<grpc::string, grpc::string> ListToDict(
const initializer_list<grpc::string>& values) {
inline std::map<std::string, std::string> ListToDict(
const initializer_list<std::string>& values) {
if (values.size() % 2 != 0) {
std::cerr << "Not every 'key' has a value in `values`." << std::endl;
}
std::map<grpc::string, grpc::string> value_map;
std::map<std::string, std::string> value_map;
auto value_iter = values.begin();
for (unsigned i = 0; i < values.size() / 2; ++i) {
grpc::string key = *value_iter;
std::string key = *value_iter;
++value_iter;
grpc::string value = *value_iter;
std::string value = *value_iter;
value_map[key] = value;
++value_iter;
}

@ -31,10 +31,10 @@ using std::transform;
namespace grpc_ruby_generator {
// Split splits a string using char into elems.
inline std::vector<grpc::string>& Split(const grpc::string& s, char delim,
std::vector<grpc::string>* elems) {
inline std::vector<std::string>& Split(const std::string& s, char delim,
std::vector<std::string>* elems) {
std::stringstream ss(s);
grpc::string item;
std::string item;
while (getline(ss, item, delim)) {
elems->push_back(item);
}
@ -42,17 +42,17 @@ inline std::vector<grpc::string>& Split(const grpc::string& s, char delim,
}
// Split splits a string using char, returning the result in a vector.
inline std::vector<grpc::string> Split(const grpc::string& s, char delim) {
std::vector<grpc::string> elems;
inline std::vector<std::string> Split(const std::string& s, char delim) {
std::vector<std::string> elems;
Split(s, delim, &elems);
return elems;
}
// Replace replaces from with to in s.
inline grpc::string Replace(grpc::string s, const grpc::string& from,
const grpc::string& to) {
inline std::string Replace(std::string s, const std::string& from,
const std::string& to) {
size_t start_pos = s.find(from);
if (start_pos == grpc::string::npos) {
if (start_pos == std::string::npos) {
return s;
}
s.replace(start_pos, from.length(), to);
@ -60,10 +60,10 @@ inline grpc::string Replace(grpc::string s, const grpc::string& from,
}
// ReplaceAll replaces all instances of search with replace in s.
inline grpc::string ReplaceAll(grpc::string s, const grpc::string& search,
const grpc::string& replace) {
inline std::string ReplaceAll(std::string s, const std::string& search,
const std::string& replace) {
size_t pos = 0;
while ((pos = s.find(search, pos)) != grpc::string::npos) {
while ((pos = s.find(search, pos)) != std::string::npos) {
s.replace(pos, search.length(), replace);
pos += replace.length();
}
@ -71,10 +71,10 @@ inline grpc::string ReplaceAll(grpc::string s, const grpc::string& search,
}
// ReplacePrefix replaces from with to in s if search is a prefix of s.
inline bool ReplacePrefix(grpc::string* s, const grpc::string& from,
const grpc::string& to) {
inline bool ReplacePrefix(std::string* s, const std::string& from,
const std::string& to) {
size_t start_pos = s->find(from);
if (start_pos == grpc::string::npos || start_pos != 0) {
if (start_pos == std::string::npos || start_pos != 0) {
return false;
}
s->replace(start_pos, from.length(), to);
@ -82,14 +82,14 @@ inline bool ReplacePrefix(grpc::string* s, const grpc::string& from,
}
// Modularize converts a string into a ruby module compatible name
inline grpc::string Modularize(grpc::string s) {
inline std::string Modularize(std::string s) {
if (s.empty()) {
return s;
}
grpc::string new_string = "";
std::string new_string = "";
bool was_last_underscore = false;
new_string.append(1, ::toupper(s[0]));
for (grpc::string::size_type i = 1; i < s.size(); ++i) {
for (std::string::size_type i = 1; i < s.size(); ++i) {
if (was_last_underscore && s[i] != '_') {
new_string.append(1, ::toupper(s[i]));
} else if (s[i] != '_') {
@ -101,8 +101,8 @@ inline grpc::string Modularize(grpc::string s) {
}
// RubyPackage gets the ruby package in either proto or ruby_package format
inline grpc::string RubyPackage(const grpc::protobuf::FileDescriptor* file) {
grpc::string package_name = file->package();
inline std::string RubyPackage(const grpc::protobuf::FileDescriptor* file) {
std::string package_name = file->package();
if (file->options().has_ruby_package()) {
package_name = file->options().ruby_package();
@ -116,8 +116,8 @@ inline grpc::string RubyPackage(const grpc::protobuf::FileDescriptor* file) {
}
// RubyTypeOf updates a proto type to the required ruby equivalent.
inline grpc::string RubyTypeOf(const grpc::protobuf::Descriptor* descriptor,
const grpc::string& package) {
inline std::string RubyTypeOf(const grpc::protobuf::Descriptor* descriptor,
const std::string& package) {
std::string proto_type = descriptor->full_name();
ReplacePrefix(&proto_type, package,
""); // remove the leading package if present
@ -125,11 +125,11 @@ inline grpc::string RubyTypeOf(const grpc::protobuf::Descriptor* descriptor,
if (descriptor->file()->options().has_ruby_package()) {
proto_type = RubyPackage(descriptor->file()) + "." + proto_type;
}
grpc::string res(proto_type);
if (res.find('.') == grpc::string::npos) {
std::string res(proto_type);
if (res.find('.') == std::string::npos) {
return res;
} else {
std::vector<grpc::string> prefixes_and_type = Split(res, '.');
std::vector<std::string> prefixes_and_type = Split(res, '.');
res.clear();
for (unsigned int i = 0; i < prefixes_and_type.size(); ++i) {
if (i != 0) {

@ -34,16 +34,16 @@ class RubyGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& /*parameter*/,
const std::string& /*parameter*/,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* /*error*/) const override {
grpc::string code = grpc_ruby_generator::GetServices(file);
std::string* /*error*/) const override {
std::string code = grpc_ruby_generator::GetServices(file);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
}
// Get output file name.
grpc::string file_name;
std::string file_name;
if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) {
return false;
}

@ -22,16 +22,20 @@
#include "src/compiler/config.h"
#include <memory>
#include <string>
#include <vector>
#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
#ifdef GRPC_CUSTOM_STRING
#warning GRPC_CUSTOM_STRING is no longer supported. Please use std::string.
#endif
namespace grpc {
typedef GRPC_CUSTOM_STRING string;
// Using grpc::string and grpc::to_string is discouraged in favor of
// std::string and std::to_string. This is only for legacy code using
// them explictly.
using std::string; // deprecated
using std::to_string; // deprecated
} // namespace grpc
@ -41,31 +45,31 @@ namespace grpc_generator {
// Return formatted comments to be inserted in generated code.
struct CommentHolder {
virtual ~CommentHolder() {}
virtual grpc::string GetLeadingComments(const grpc::string prefix) const = 0;
virtual grpc::string GetTrailingComments(const grpc::string prefix) const = 0;
virtual std::vector<grpc::string> GetAllComments() const = 0;
virtual std::string GetLeadingComments(const std::string prefix) const = 0;
virtual std::string GetTrailingComments(const std::string prefix) const = 0;
virtual std::vector<std::string> GetAllComments() const = 0;
};
// An abstract interface representing a method.
struct Method : public CommentHolder {
virtual ~Method() {}
virtual grpc::string name() const = 0;
virtual std::string name() const = 0;
virtual grpc::string input_type_name() const = 0;
virtual grpc::string output_type_name() const = 0;
virtual std::string input_type_name() const = 0;
virtual std::string output_type_name() const = 0;
virtual bool get_module_and_message_path_input(
grpc::string* str, grpc::string generator_file_name,
bool generate_in_pb2_grpc, grpc::string import_prefix,
const std::vector<grpc::string>& prefixes_to_filter) const = 0;
std::string* str, std::string generator_file_name,
bool generate_in_pb2_grpc, std::string import_prefix,
const std::vector<std::string>& prefixes_to_filter) const = 0;
virtual bool get_module_and_message_path_output(
grpc::string* str, grpc::string generator_file_name,
bool generate_in_pb2_grpc, grpc::string import_prefix,
const std::vector<grpc::string>& prefixes_to_filter) const = 0;
std::string* str, std::string generator_file_name,
bool generate_in_pb2_grpc, std::string import_prefix,
const std::vector<std::string>& prefixes_to_filter) const = 0;
virtual grpc::string get_input_type_name() const = 0;
virtual grpc::string get_output_type_name() const = 0;
virtual std::string get_input_type_name() const = 0;
virtual std::string get_output_type_name() const = 0;
virtual bool NoStreaming() const = 0;
virtual bool ClientStreaming() const = 0;
virtual bool ServerStreaming() const = 0;
@ -76,7 +80,7 @@ struct Method : public CommentHolder {
struct Service : public CommentHolder {
virtual ~Service() {}
virtual grpc::string name() const = 0;
virtual std::string name() const = 0;
virtual int method_count() const = 0;
virtual std::unique_ptr<const Method> method(int i) const = 0;
@ -85,7 +89,7 @@ struct Service : public CommentHolder {
struct Printer {
virtual ~Printer() {}
virtual void Print(const std::map<grpc::string, grpc::string>& vars,
virtual void Print(const std::map<std::string, std::string>& vars,
const char* template_string) = 0;
virtual void Print(const char* string) = 0;
virtual void PrintRaw(const char* string) = 0;
@ -98,17 +102,17 @@ struct Printer {
struct File : public CommentHolder {
virtual ~File() {}
virtual grpc::string filename() const = 0;
virtual grpc::string filename_without_ext() const = 0;
virtual grpc::string package() const = 0;
virtual std::vector<grpc::string> package_parts() const = 0;
virtual grpc::string additional_headers() const = 0;
virtual std::vector<grpc::string> GetImportNames() const { return {}; }
virtual std::string filename() const = 0;
virtual std::string filename_without_ext() const = 0;
virtual std::string package() const = 0;
virtual std::vector<std::string> package_parts() const = 0;
virtual std::string additional_headers() const = 0;
virtual std::vector<std::string> GetImportNames() const { return {}; }
virtual int service_count() const = 0;
virtual std::unique_ptr<const Service> service(int i) const = 0;
virtual std::unique_ptr<Printer> CreatePrinter(grpc::string* str) const = 0;
virtual std::unique_ptr<Printer> CreatePrinter(std::string* str) const = 0;
};
} // namespace grpc_generator

@ -48,7 +48,7 @@ void ::grpc::experimental::ChannelResetConnectionBackoff(Channel* channel) {
namespace grpc_impl {
static ::grpc::internal::GrpcLibraryInitializer g_gli_initializer;
Channel::Channel(const grpc::string& host, grpc_channel* channel,
Channel::Channel(const std::string& host, grpc_channel* channel,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators)
@ -71,28 +71,28 @@ inline grpc_slice SliceFromArray(const char* arr, size_t len) {
len);
}
grpc::string GetChannelInfoField(grpc_channel* channel,
grpc_channel_info* channel_info,
char*** channel_info_field) {
std::string GetChannelInfoField(grpc_channel* channel,
grpc_channel_info* channel_info,
char*** channel_info_field) {
char* value = nullptr;
memset(channel_info, 0, sizeof(*channel_info));
*channel_info_field = &value;
grpc_channel_get_info(channel, channel_info);
if (value == nullptr) return "";
grpc::string result = value;
std::string result = value;
gpr_free(value);
return result;
}
} // namespace
grpc::string Channel::GetLoadBalancingPolicyName() const {
std::string Channel::GetLoadBalancingPolicyName() const {
grpc_channel_info channel_info;
return GetChannelInfoField(c_channel_, &channel_info,
&channel_info.lb_policy_name);
}
grpc::string Channel::GetServiceConfigJSON() const {
std::string Channel::GetServiceConfigJSON() const {
grpc_channel_info channel_info;
return GetChannelInfoField(c_channel_, &channel_info,
&channel_info.service_config_json);
@ -117,7 +117,7 @@ void ChannelResetConnectionBackoff(Channel* channel) {
context->propagation_options_.c_bitmask(), cq->cq(),
method.channel_tag(), context->raw_deadline(), nullptr);
} else {
const ::grpc::string* host_str = nullptr;
const ::std::string* host_str = nullptr;
if (!context->authority_.empty()) {
host_str = &context->authority_;
} else if (!host_.empty()) {

@ -108,8 +108,8 @@ std::unique_ptr<ClientContext> ClientContext::FromCallbackServerContext(
return FromInternalServerContext(server_context, options);
}
void ClientContext::AddMetadata(const grpc::string& meta_key,
const grpc::string& meta_value) {
void ClientContext::AddMetadata(const std::string& meta_key,
const std::string& meta_value) {
send_initial_metadata_.insert(std::make_pair(meta_key, meta_value));
}
@ -161,8 +161,8 @@ void ClientContext::SendCancelToInterceptors() {
}
}
grpc::string ClientContext::peer() const {
grpc::string peer;
std::string ClientContext::peer() const {
std::string peer;
if (call_) {
char* c_peer = grpc_call_get_peer(call_);
peer = c_peer;

@ -28,13 +28,13 @@
namespace grpc_impl {
std::shared_ptr<grpc::Channel> CreateChannelImpl(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds) {
return CreateCustomChannelImpl(target, creds, grpc::ChannelArguments());
}
std::shared_ptr<grpc::Channel> CreateCustomChannelImpl(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args) {
grpc::GrpcLibraryCodegen
@ -63,7 +63,7 @@ namespace experimental {
/// fail) is returned.
/// \param args Options for channel creation.
std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors(
const grpc::string& target,
const std::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args,
std::vector<

@ -25,7 +25,7 @@ struct grpc_channel;
namespace grpc {
std::shared_ptr<Channel> CreateChannelInternal(
const grpc::string& host, grpc_channel* c_channel,
const std::string& host, grpc_channel* c_channel,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) {

@ -30,7 +30,7 @@ struct grpc_channel;
namespace grpc {
std::shared_ptr<Channel> CreateChannelInternal(
const grpc::string& host, grpc_channel* c_channel,
const std::string& host, grpc_channel* c_channel,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);

@ -33,7 +33,7 @@ namespace grpc {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD
std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
std::shared_ptr<Channel> CreateInsecureChannelFromFd(const std::string& target,
int fd) {
grpc::internal::GrpcLibrary init_lib;
init_lib.init();
@ -44,7 +44,7 @@ std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
}
std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
const grpc::string& target, int fd, const grpc::ChannelArguments& args) {
const std::string& target, int fd, const grpc::ChannelArguments& args) {
internal::GrpcLibrary init_lib;
init_lib.init();
grpc_channel_args channel_args;
@ -59,7 +59,7 @@ std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
namespace experimental {
std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd(
const grpc::string& target, int fd, const ChannelArguments& args,
const std::string& target, int fd, const ChannelArguments& args,
std::vector<
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) {

@ -30,7 +30,7 @@ namespace {
class InsecureChannelCredentialsImpl final : public ChannelCredentials {
public:
std::shared_ptr<Channel> CreateChannelImpl(
const grpc::string& target, const ChannelArguments& args) override {
const std::string& target, const ChannelArguments& args) override {
return CreateChannelWithInterceptors(
target, args,
std::vector<std::unique_ptr<
@ -38,7 +38,7 @@ class InsecureChannelCredentialsImpl final : public ChannelCredentials {
}
std::shared_ptr<Channel> CreateChannelWithInterceptors(
const grpc::string& target, const ChannelArguments& args,
const std::string& target, const ChannelArguments& args,
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) override {

@ -48,7 +48,7 @@ SecureChannelCredentials::SecureChannelCredentials(
}
std::shared_ptr<Channel> SecureChannelCredentials::CreateChannelImpl(
const grpc::string& target, const ChannelArguments& args) {
const std::string& target, const ChannelArguments& args) {
return CreateChannelWithInterceptors(
target, args,
std::vector<std::unique_ptr<
@ -57,7 +57,7 @@ std::shared_ptr<Channel> SecureChannelCredentials::CreateChannelImpl(
std::shared_ptr<Channel>
SecureChannelCredentials::CreateChannelWithInterceptors(
const grpc::string& target, const ChannelArguments& args,
const std::string& target, const ChannelArguments& args,
std::vector<
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) {
@ -134,7 +134,7 @@ void ClearStsCredentialsOptions(StsCredentialsOptions* options) {
} // namespace
// Builds STS credentials options from JSON.
grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string,
grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string,
StsCredentialsOptions* options) {
if (options == nullptr) {
return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
@ -304,7 +304,7 @@ std::shared_ptr<CallCredentials> GoogleComputeEngineCredentials() {
// Builds JWT credentials.
std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials(
const grpc::string& json_key, long token_lifetime_seconds) {
const std::string& json_key, long token_lifetime_seconds) {
grpc::GrpcLibraryCodegen init; // To call grpc_init().
if (token_lifetime_seconds <= 0) {
gpr_log(GPR_ERROR,
@ -319,7 +319,7 @@ std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials(
// Builds refresh token credentials.
std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials(
const grpc::string& json_refresh_token) {
const std::string& json_refresh_token) {
grpc::GrpcLibraryCodegen init; // To call grpc_init().
return WrapCallCredentials(grpc_google_refresh_token_credentials_create(
json_refresh_token.c_str(), nullptr));
@ -327,7 +327,7 @@ std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials(
// Builds access token credentials.
std::shared_ptr<CallCredentials> AccessTokenCredentials(
const grpc::string& access_token) {
const std::string& access_token) {
grpc::GrpcLibraryCodegen init; // To call grpc_init().
return WrapCallCredentials(
grpc_access_token_credentials_create(access_token.c_str(), nullptr));
@ -335,8 +335,8 @@ std::shared_ptr<CallCredentials> AccessTokenCredentials(
// Builds IAM credentials.
std::shared_ptr<CallCredentials> GoogleIAMCredentials(
const grpc::string& authorization_token,
const grpc::string& authority_selector) {
const std::string& authorization_token,
const std::string& authority_selector) {
grpc::GrpcLibraryCodegen init; // To call grpc_init().
return WrapCallCredentials(grpc_google_iam_credentials_create(
authorization_token.c_str(), authority_selector.c_str(), nullptr));
@ -463,7 +463,7 @@ void MetadataCredentialsPluginWrapper::InvokePlugin(
grpc_auth_metadata_context context, grpc_credentials_plugin_metadata_cb cb,
void* user_data, grpc_metadata creds_md[4], size_t* num_creds_md,
grpc_status_code* status_code, const char** error_details) {
std::multimap<grpc::string, grpc::string> metadata;
std::multimap<std::string, std::string> metadata;
// const_cast is safe since the SecureAuthContext only inc/dec the refcount
// and the object is passed as a const ref to plugin_->GetMetadata.

@ -43,13 +43,13 @@ class SecureChannelCredentials final : public ChannelCredentials {
grpc_channel_credentials* GetRawCreds() { return c_creds_; }
std::shared_ptr<Channel> CreateChannelImpl(
const grpc::string& target, const ChannelArguments& args) override;
const std::string& target, const ChannelArguments& args) override;
SecureChannelCredentials* AsSecureCredentials() override { return this; }
private:
std::shared_ptr<Channel> CreateChannelWithInterceptors(
const grpc::string& target, const ChannelArguments& args,
const std::string& target, const ChannelArguments& args,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) override;
@ -66,9 +66,9 @@ class SecureCallCredentials final : public CallCredentials {
bool ApplyToCall(grpc_call* call) override;
SecureCallCredentials* AsSecureCredentials() override { return this; }
grpc::string DebugString() override {
std::string DebugString() override {
return absl::StrCat("SecureCallCredentials{",
grpc::string(c_creds_->debug_string()), "}");
std::string(c_creds_->debug_string()), "}");
}
private:

@ -33,23 +33,23 @@ AltsContext::AltsContext(const grpc_gcp_AltsContext* ctx) {
grpc_gcp_AltsContext_application_protocol(ctx);
if (application_protocol.data != nullptr && application_protocol.size > 0) {
application_protocol_ =
grpc::string(application_protocol.data, application_protocol.size);
std::string(application_protocol.data, application_protocol.size);
}
upb_strview record_protocol = grpc_gcp_AltsContext_record_protocol(ctx);
if (record_protocol.data != nullptr && record_protocol.size > 0) {
record_protocol_ = grpc::string(record_protocol.data, record_protocol.size);
record_protocol_ = std::string(record_protocol.data, record_protocol.size);
}
upb_strview peer_service_account =
grpc_gcp_AltsContext_peer_service_account(ctx);
if (peer_service_account.data != nullptr && peer_service_account.size > 0) {
peer_service_account_ =
grpc::string(peer_service_account.data, peer_service_account.size);
std::string(peer_service_account.data, peer_service_account.size);
}
upb_strview local_service_account =
grpc_gcp_AltsContext_local_service_account(ctx);
if (local_service_account.data != nullptr && local_service_account.size > 0) {
local_service_account_ =
grpc::string(local_service_account.data, local_service_account.size);
std::string(local_service_account.data, local_service_account.size);
}
const grpc_gcp_RpcProtocolVersions* versions =
grpc_gcp_AltsContext_peer_rpc_versions(ctx);
@ -82,17 +82,17 @@ AltsContext::AltsContext(const grpc_gcp_AltsContext* ctx) {
}
}
grpc::string AltsContext::application_protocol() const {
std::string AltsContext::application_protocol() const {
return application_protocol_;
}
grpc::string AltsContext::record_protocol() const { return record_protocol_; }
std::string AltsContext::record_protocol() const { return record_protocol_; }
grpc::string AltsContext::peer_service_account() const {
std::string AltsContext::peer_service_account() const {
return peer_service_account_;
}
grpc::string AltsContext::local_service_account() const {
std::string AltsContext::local_service_account() const {
return local_service_account_;
}

@ -97,7 +97,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) {
grpc_core::ExecCtx exec_ctx;
for (auto& arg : args_) {
if (arg.type == mutator_arg.type &&
grpc::string(arg.key) == grpc::string(mutator_arg.key)) {
std::string(arg.key) == std::string(mutator_arg.key)) {
GPR_ASSERT(!replaced);
arg.value.pointer.vtable->destroy(arg.value.pointer.p);
arg.value.pointer = mutator_arg.value.pointer;
@ -106,7 +106,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) {
}
if (!replaced) {
strings_.push_back(grpc::string(mutator_arg.key));
strings_.push_back(std::string(mutator_arg.key));
args_.push_back(mutator_arg);
args_.back().key = const_cast<char*>(strings_.back().c_str());
}
@ -117,7 +117,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) {
// prefix. The user can build up a prefix string by calling this multiple times,
// each with more significant identifier.
void ChannelArguments::SetUserAgentPrefix(
const grpc::string& user_agent_prefix) {
const std::string& user_agent_prefix) {
if (user_agent_prefix.empty()) {
return;
}
@ -126,7 +126,7 @@ void ChannelArguments::SetUserAgentPrefix(
for (auto& arg : args_) {
++strings_it;
if (arg.type == GRPC_ARG_STRING) {
if (grpc::string(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) {
if (std::string(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) {
GPR_ASSERT(arg.value.string == strings_it->c_str());
*(strings_it) = user_agent_prefix + " " + arg.value.string;
arg.value.string = const_cast<char*>(strings_it->c_str());
@ -157,16 +157,16 @@ void ChannelArguments::SetMaxSendMessageSize(int size) {
}
void ChannelArguments::SetLoadBalancingPolicyName(
const grpc::string& lb_policy_name) {
const std::string& lb_policy_name) {
SetString(GRPC_ARG_LB_POLICY_NAME, lb_policy_name);
}
void ChannelArguments::SetServiceConfigJSON(
const grpc::string& service_config_json) {
const std::string& service_config_json) {
SetString(GRPC_ARG_SERVICE_CONFIG, service_config_json);
}
void ChannelArguments::SetInt(const grpc::string& key, int value) {
void ChannelArguments::SetInt(const std::string& key, int value) {
grpc_arg arg;
arg.type = GRPC_ARG_INTEGER;
strings_.push_back(key);
@ -176,7 +176,7 @@ void ChannelArguments::SetInt(const grpc::string& key, int value) {
args_.push_back(arg);
}
void ChannelArguments::SetPointer(const grpc::string& key, void* value) {
void ChannelArguments::SetPointer(const std::string& key, void* value) {
static const grpc_arg_pointer_vtable vtable = {
&PointerVtableMembers::Copy, &PointerVtableMembers::Destroy,
&PointerVtableMembers::Compare};
@ -184,7 +184,7 @@ void ChannelArguments::SetPointer(const grpc::string& key, void* value) {
}
void ChannelArguments::SetPointerWithVtable(
const grpc::string& key, void* value,
const std::string& key, void* value,
const grpc_arg_pointer_vtable* vtable) {
grpc_arg arg;
arg.type = GRPC_ARG_POINTER;
@ -195,8 +195,8 @@ void ChannelArguments::SetPointerWithVtable(
args_.push_back(arg);
}
void ChannelArguments::SetString(const grpc::string& key,
const grpc::string& value) {
void ChannelArguments::SetString(const std::string& key,
const std::string& value) {
grpc_arg arg;
arg.type = GRPC_ARG_STRING;
strings_.push_back(key);

@ -23,7 +23,7 @@ namespace grpc {
ResourceQuota::ResourceQuota() : impl_(grpc_resource_quota_create(nullptr)) {}
ResourceQuota::ResourceQuota(const grpc::string& name)
ResourceQuota::ResourceQuota(const std::string& name)
: impl_(grpc_resource_quota_create(name.c_str())) {}
ResourceQuota::~ResourceQuota() { grpc_resource_quota_unref(impl_); }

@ -37,7 +37,7 @@ std::vector<grpc::string_ref> SecureAuthContext::GetPeerIdentity() const {
return identity;
}
grpc::string SecureAuthContext::GetPeerIdentityPropertyName() const {
std::string SecureAuthContext::GetPeerIdentityPropertyName() const {
if (ctx_ == nullptr) {
return "";
}
@ -46,7 +46,7 @@ grpc::string SecureAuthContext::GetPeerIdentityPropertyName() const {
}
std::vector<grpc::string_ref> SecureAuthContext::FindPropertyValues(
const grpc::string& name) const {
const std::string& name) const {
if (ctx_ == nullptr) {
return std::vector<grpc::string_ref>();
}
@ -76,14 +76,14 @@ AuthPropertyIterator SecureAuthContext::end() const {
return AuthPropertyIterator();
}
void SecureAuthContext::AddProperty(const grpc::string& key,
void SecureAuthContext::AddProperty(const std::string& key,
const grpc::string_ref& value) {
if (ctx_ == nullptr) return;
grpc_auth_context_add_property(ctx_.get(), key.c_str(), value.data(),
value.size());
}
bool SecureAuthContext::SetPeerIdentityPropertyName(const grpc::string& name) {
bool SecureAuthContext::SetPeerIdentityPropertyName(const std::string& name) {
if (ctx_ == nullptr) return false;
return grpc_auth_context_set_peer_identity_property_name(ctx_.get(),
name.c_str()) != 0;

@ -37,19 +37,19 @@ class SecureAuthContext final : public AuthContext {
std::vector<grpc::string_ref> GetPeerIdentity() const override;
grpc::string GetPeerIdentityPropertyName() const override;
std::string GetPeerIdentityPropertyName() const override;
std::vector<grpc::string_ref> FindPropertyValues(
const grpc::string& name) const override;
const std::string& name) const override;
AuthPropertyIterator begin() const override;
AuthPropertyIterator end() const override;
void AddProperty(const grpc::string& key,
void AddProperty(const std::string& key,
const grpc::string_ref& value) override;
virtual bool SetPeerIdentityPropertyName(const grpc::string& name) override;
virtual bool SetPeerIdentityPropertyName(const std::string& name) override;
private:
grpc_core::RefCountedPtr<grpc_auth_context> ctx_;

@ -23,13 +23,13 @@
namespace grpc_impl {
void ChannelArguments::SetSslTargetNameOverride(const grpc::string& name) {
void ChannelArguments::SetSslTargetNameOverride(const std::string& name) {
SetString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, name);
}
grpc::string ChannelArguments::GetSslTargetNameOverride() const {
std::string ChannelArguments::GetSslTargetNameOverride() const {
for (unsigned int i = 0; i < args_.size(); i++) {
if (grpc::string(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == args_[i].key) {
if (std::string(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == args_[i].key) {
return args_[i].value.string;
}
}

@ -28,7 +28,7 @@ namespace experimental {
/** TLS key materials config API implementation **/
void TlsKeyMaterialsConfig::set_pem_root_certs(
const grpc::string& pem_root_certs) {
const std::string& pem_root_certs) {
pem_root_certs_ = pem_root_certs;
}
@ -38,7 +38,7 @@ void TlsKeyMaterialsConfig::add_pem_key_cert_pair(
}
void TlsKeyMaterialsConfig::set_key_materials(
const grpc::string& pem_root_certs,
const std::string& pem_root_certs,
const std::vector<PemKeyCertPair>& pem_key_cert_pair_list) {
pem_key_cert_pair_list_ = pem_key_cert_pair_list;
pem_root_certs_ = pem_root_certs;
@ -69,7 +69,7 @@ grpc_ssl_certificate_config_reload_status TlsCredentialReloadArg::status()
return c_arg_->status;
}
grpc::string TlsCredentialReloadArg::error_details() const {
std::string TlsCredentialReloadArg::error_details() const {
return c_arg_->error_details->error_details();
}
@ -78,7 +78,7 @@ void TlsCredentialReloadArg::set_cb_user_data(void* cb_user_data) {
}
void TlsCredentialReloadArg::set_pem_root_certs(
const grpc::string& pem_root_certs) {
const std::string& pem_root_certs) {
::grpc_core::UniquePtr<char> c_pem_root_certs(
gpr_strdup(pem_root_certs.c_str()));
c_arg_->key_materials_config->set_pem_root_certs(std::move(c_pem_root_certs));
@ -105,7 +105,7 @@ void TlsCredentialReloadArg::add_pem_key_cert_pair(
}
void TlsCredentialReloadArg::set_key_materials(
const grpc::string& pem_root_certs,
const std::string& pem_root_certs,
std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> pem_key_cert_pair_list) {
/** Initialize the |key_materials_config| field of |c_arg_|, if it has not
* already been done. **/
@ -159,7 +159,7 @@ void TlsCredentialReloadArg::set_status(
}
void TlsCredentialReloadArg::set_error_details(
const grpc::string& error_details) {
const std::string& error_details) {
c_arg_->error_details->set_error_details(error_details.c_str());
}
@ -202,18 +202,18 @@ void* TlsServerAuthorizationCheckArg::cb_user_data() const {
int TlsServerAuthorizationCheckArg::success() const { return c_arg_->success; }
grpc::string TlsServerAuthorizationCheckArg::target_name() const {
grpc::string cpp_target_name(c_arg_->target_name);
std::string TlsServerAuthorizationCheckArg::target_name() const {
std::string cpp_target_name(c_arg_->target_name);
return cpp_target_name;
}
grpc::string TlsServerAuthorizationCheckArg::peer_cert() const {
grpc::string cpp_peer_cert(c_arg_->peer_cert);
std::string TlsServerAuthorizationCheckArg::peer_cert() const {
std::string cpp_peer_cert(c_arg_->peer_cert);
return cpp_peer_cert;
}
grpc::string TlsServerAuthorizationCheckArg::peer_cert_full_chain() const {
grpc::string cpp_peer_cert_full_chain(c_arg_->peer_cert_full_chain);
std::string TlsServerAuthorizationCheckArg::peer_cert_full_chain() const {
std::string cpp_peer_cert_full_chain(c_arg_->peer_cert_full_chain);
return cpp_peer_cert_full_chain;
}
@ -221,7 +221,7 @@ grpc_status_code TlsServerAuthorizationCheckArg::status() const {
return c_arg_->status;
}
grpc::string TlsServerAuthorizationCheckArg::error_details() const {
std::string TlsServerAuthorizationCheckArg::error_details() const {
return c_arg_->error_details->error_details();
}
@ -234,17 +234,17 @@ void TlsServerAuthorizationCheckArg::set_success(int success) {
}
void TlsServerAuthorizationCheckArg::set_target_name(
const grpc::string& target_name) {
const std::string& target_name) {
c_arg_->target_name = gpr_strdup(target_name.c_str());
}
void TlsServerAuthorizationCheckArg::set_peer_cert(
const grpc::string& peer_cert) {
const std::string& peer_cert) {
c_arg_->peer_cert = gpr_strdup(peer_cert.c_str());
}
void TlsServerAuthorizationCheckArg::set_peer_cert_full_chain(
const grpc::string& peer_cert_full_chain) {
const std::string& peer_cert_full_chain) {
c_arg_->peer_cert_full_chain = gpr_strdup(peer_cert_full_chain.c_str());
}
@ -253,7 +253,7 @@ void TlsServerAuthorizationCheckArg::set_status(grpc_status_code status) {
}
void TlsServerAuthorizationCheckArg::set_error_details(
const grpc::string& error_details) {
const std::string& error_details) {
c_arg_->error_details->set_error_details(error_details.c_str());
}

@ -23,12 +23,11 @@
namespace grpc {
namespace experimental {
grpc::string ValidateServiceConfigJSON(
const grpc::string& service_config_json) {
std::string ValidateServiceConfigJSON(const std::string& service_config_json) {
grpc_init();
grpc_error* error = GRPC_ERROR_NONE;
grpc_core::ServiceConfig::Create(service_config_json.c_str(), &error);
grpc::string return_value;
std::string return_value;
if (error != GRPC_ERROR_NONE) {
return_value = grpc_error_string(error);
GRPC_ERROR_UNREF(error);

@ -22,5 +22,5 @@
#include <grpcpp/grpcpp.h>
namespace grpc {
grpc::string Version() { return "1.31.0-dev"; }
std::string Version() { return "1.31.0-dev"; }
} // namespace grpc

@ -40,7 +40,7 @@ ProtoServerReflection::ProtoServerReflection()
: descriptor_pool_(protobuf::DescriptorPool::generated_pool()) {}
void ProtoServerReflection::SetServiceList(
const std::vector<grpc::string>* services) {
const std::vector<std::string>* services) {
services_ = services;
}
@ -110,7 +110,7 @@ Status ProtoServerReflection::ListService(ServerContext* /*context*/,
}
Status ProtoServerReflection::GetFileByName(
ServerContext* /*context*/, const grpc::string& filename,
ServerContext* /*context*/, const std::string& filename,
ServerReflectionResponse* response) {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
@ -121,13 +121,13 @@ Status ProtoServerReflection::GetFileByName(
if (file_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "File not found.");
}
std::unordered_set<grpc::string> seen_files;
std::unordered_set<std::string> seen_files;
FillFileDescriptorResponse(file_desc, response, &seen_files);
return Status::OK;
}
Status ProtoServerReflection::GetFileContainingSymbol(
ServerContext* /*context*/, const grpc::string& symbol,
ServerContext* /*context*/, const std::string& symbol,
ServerReflectionResponse* response) {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
@ -138,7 +138,7 @@ Status ProtoServerReflection::GetFileContainingSymbol(
if (file_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Symbol not found.");
}
std::unordered_set<grpc::string> seen_files;
std::unordered_set<std::string> seen_files;
FillFileDescriptorResponse(file_desc, response, &seen_files);
return Status::OK;
}
@ -162,13 +162,13 @@ Status ProtoServerReflection::GetFileContainingExtension(
if (field_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Extension not found.");
}
std::unordered_set<grpc::string> seen_files;
std::unordered_set<std::string> seen_files;
FillFileDescriptorResponse(field_desc->file(), response, &seen_files);
return Status::OK;
}
Status ProtoServerReflection::GetAllExtensionNumbers(
ServerContext* /*context*/, const grpc::string& type,
ServerContext* /*context*/, const std::string& type,
ExtensionNumberResponse* response) {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
@ -192,14 +192,14 @@ Status ProtoServerReflection::GetAllExtensionNumbers(
void ProtoServerReflection::FillFileDescriptorResponse(
const protobuf::FileDescriptor* file_desc,
ServerReflectionResponse* response,
std::unordered_set<grpc::string>* seen_files) {
std::unordered_set<std::string>* seen_files) {
if (seen_files->find(file_desc->name()) != seen_files->end()) {
return;
}
seen_files->insert(file_desc->name());
protobuf::FileDescriptorProto file_desc_proto;
grpc::string data;
std::string data;
file_desc->CopyTo(&file_desc_proto);
file_desc_proto.SerializeToString(&data);
response->mutable_file_descriptor_response()->add_file_descriptor_proto(data);

@ -33,7 +33,7 @@ class ProtoServerReflection final
ProtoServerReflection();
// Add the full names of registered services
void SetServiceList(const std::vector<grpc::string>* services);
void SetServiceList(const std::vector<std::string>* services);
// implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc
// in ServerReflection service
@ -47,11 +47,11 @@ class ProtoServerReflection final
Status ListService(ServerContext* context,
reflection::v1alpha::ListServiceResponse* response);
Status GetFileByName(ServerContext* context, const grpc::string& file_name,
Status GetFileByName(ServerContext* context, const std::string& file_name,
reflection::v1alpha::ServerReflectionResponse* response);
Status GetFileContainingSymbol(
ServerContext* context, const grpc::string& symbol,
ServerContext* context, const std::string& symbol,
reflection::v1alpha::ServerReflectionResponse* response);
Status GetFileContainingExtension(
@ -60,13 +60,13 @@ class ProtoServerReflection final
reflection::v1alpha::ServerReflectionResponse* response);
Status GetAllExtensionNumbers(
ServerContext* context, const grpc::string& type,
ServerContext* context, const std::string& type,
reflection::v1alpha::ExtensionNumberResponse* response);
void FillFileDescriptorResponse(
const protobuf::FileDescriptor* file_desc,
reflection::v1alpha::ServerReflectionResponse* response,
std::unordered_set<grpc::string>* seen_files);
std::unordered_set<std::string>* seen_files);
void FillErrorResponse(const Status& status,
reflection::v1alpha::ErrorResponse* error_response);

@ -29,7 +29,7 @@ namespace reflection {
ProtoServerReflectionPlugin::ProtoServerReflectionPlugin()
: reflection_service_(new grpc::ProtoServerReflection()) {}
grpc::string ProtoServerReflectionPlugin::name() {
std::string ProtoServerReflectionPlugin::name() {
return "proto_server_reflection";
}
@ -41,7 +41,7 @@ void ProtoServerReflectionPlugin::Finish(grpc::ServerInitializer* si) {
reflection_service_->SetServiceList(si->GetServiceList());
}
void ProtoServerReflectionPlugin::ChangeArguments(const grpc::string& /*name*/,
void ProtoServerReflectionPlugin::ChangeArguments(const std::string& /*name*/,
void* /*value*/) {}
bool ProtoServerReflectionPlugin::has_sync_methods() const {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save