diff options
author | Craig Tiller <ctiller@google.com> | 2015-08-26 08:22:42 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-08-26 08:22:42 -0700 |
commit | afbbaf9c3e21b6a4fe41242df9d052e077dc25c0 (patch) | |
tree | 155223718dd74cd94657fbd422275f052a800e7b /include | |
parent | f1c76741e8b006964679acdf34e6831e80f39766 (diff) | |
parent | 9f8c100ea86aa439e1200d2111d22354f52351cf (diff) |
Merge pull request #3065 from yang-g/string_ref
Use string_ref for incoming metadata
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/client_context.h | 11 | ||||
-rw-r--r-- | include/grpc++/impl/call.h | 9 | ||||
-rw-r--r-- | include/grpc++/server_context.h | 5 | ||||
-rw-r--r-- | include/grpc++/support/string_ref.h | 28 |
4 files changed, 28 insertions, 25 deletions
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index ee28f360cb..62e5260a18 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -45,6 +45,7 @@ #include <grpc++/support/auth_context.h> #include <grpc++/support/config.h> #include <grpc++/support/status.h> +#include <grpc++/support/string_ref.h> #include <grpc++/support/time.h> struct census_context; @@ -138,12 +139,14 @@ class ClientContext { void AddMetadata(const grpc::string& meta_key, const grpc::string& meta_value); - const std::multimap<grpc::string, grpc::string>& GetServerInitialMetadata() { + const std::multimap<grpc::string_ref, grpc::string_ref>& + GetServerInitialMetadata() { GPR_ASSERT(initial_metadata_received_); return recv_initial_metadata_; } - const std::multimap<grpc::string, grpc::string>& GetServerTrailingMetadata() { + const std::multimap<grpc::string_ref, grpc::string_ref>& + GetServerTrailingMetadata() { // TODO(yangg) check finished return trailing_metadata_; } @@ -234,8 +237,8 @@ class ClientContext { mutable std::shared_ptr<const AuthContext> auth_context_; struct census_context* census_context_; std::multimap<grpc::string, grpc::string> send_initial_metadata_; - std::multimap<grpc::string, grpc::string> recv_initial_metadata_; - std::multimap<grpc::string, grpc::string> trailing_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref> recv_initial_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref> trailing_metadata_; grpc_call* propagate_from_call_; PropagationOptions propagation_options_; diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index e5da6c9e2a..fca5603047 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -54,8 +54,9 @@ namespace grpc { class ByteBuffer; class Call; -void FillMetadataMap(grpc_metadata_array* arr, - std::multimap<grpc::string, grpc::string>* metadata); +void FillMetadataMap( + grpc_metadata_array* arr, + std::multimap<grpc::string_ref, grpc::string_ref>* metadata); grpc_metadata* FillMetadataArray( const std::multimap<grpc::string, grpc::string>& metadata); @@ -418,7 +419,7 @@ class CallOpRecvInitialMetadata { } private: - std::multimap<grpc::string, grpc::string>* recv_initial_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref>* recv_initial_metadata_; grpc_metadata_array recv_initial_metadata_arr_; }; @@ -461,7 +462,7 @@ class CallOpClientRecvStatus { } private: - std::multimap<grpc::string, grpc::string>* recv_trailing_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref>* recv_trailing_metadata_; Status* recv_status_; grpc_metadata_array recv_trailing_metadata_arr_; grpc_status_code status_code_; diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index ce3cb47a23..4b17a28047 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -41,6 +41,7 @@ #include <grpc/support/time.h> #include <grpc++/support/auth_context.h> #include <grpc++/support/config.h> +#include <grpc++/support/string_ref.h> #include <grpc++/support/time.h> struct gpr_timespec; @@ -103,7 +104,7 @@ class ServerContext { bool IsCancelled() const; - const std::multimap<grpc::string, grpc::string>& client_metadata() { + const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata() { return client_metadata_; } @@ -185,7 +186,7 @@ class ServerContext { CompletionQueue* cq_; bool sent_initial_metadata_; mutable std::shared_ptr<const AuthContext> auth_context_; - std::multimap<grpc::string, grpc::string> client_metadata_; + std::multimap<grpc::string_ref, grpc::string_ref> client_metadata_; std::multimap<grpc::string, grpc::string> initial_metadata_; std::multimap<grpc::string, grpc::string> trailing_metadata_; diff --git a/include/grpc++/support/string_ref.h b/include/grpc++/support/string_ref.h index 0ec39a9b0a..348c42cbba 100644 --- a/include/grpc++/support/string_ref.h +++ b/include/grpc++/support/string_ref.h @@ -50,22 +50,22 @@ class string_ref { typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // constants - static constexpr size_t npos = size_t(-1); + const static size_t npos = size_t(-1); // construct/copy. - constexpr string_ref() : data_(nullptr), length_(0) {} - constexpr string_ref(const string_ref& other) + string_ref() : data_(nullptr), length_(0) {} + string_ref(const string_ref& other) : data_(other.data_), length_(other.length_) {} string_ref& operator=(const string_ref& rhs); string_ref(const char* s); - constexpr string_ref(const char* s, size_t l) : data_(s), length_(l) {} + string_ref(const char* s, size_t l) : data_(s), length_(l) {} string_ref(const grpc::string& s) : data_(s.data()), length_(s.length()) {} // iterators - constexpr const_iterator begin() const { return data_; } - constexpr const_iterator end() const { return data_ + length_; } - constexpr const_iterator cbegin() const { return data_; } - constexpr const_iterator cend() const { return data_ + length_; } + const_iterator begin() const { return data_; } + const_iterator end() const { return data_ + length_; } + const_iterator cbegin() const { return data_; } + const_iterator cend() const { return data_ + length_; } const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } @@ -80,10 +80,10 @@ class string_ref { } // capacity - constexpr size_t size() const { return length_; } - constexpr size_t length() const { return length_; } - constexpr size_t max_size() const { return length_; } - constexpr bool empty() const { return length_ == 0; } + size_t size() const { return length_; } + size_t length() const { return length_; } + size_t max_size() const { return length_; } + bool empty() const { return length_ == 0; } // element access const char* data() const { return data_; } @@ -95,9 +95,7 @@ class string_ref { size_t find(string_ref s) const; size_t find(char c) const; - // Defined as constexpr in n3442 but C++11 constexpr semantics do not allow - // the implementation of this function to comply. - /* constrexpr */ string_ref substr(size_t pos, size_t n = npos) const; + string_ref substr(size_t pos, size_t n = npos) const; private: const char* data_; |