diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-06-04 16:19:22 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-06-04 16:19:22 -0700 |
commit | 789471cfc64cd0200a53914939a0485846b5a80f (patch) | |
tree | dcd82e74ceddc6f73dcbe0a5b14dc3ef61fe2864 /src | |
parent | e850f3caad7db8cb353a42479c3e03704e8dc1e8 (diff) |
Client side compiles/links
Diffstat (limited to 'src')
-rw-r--r-- | src/cpp/common/call.cc | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc index dc3d36faa2..3f3f5279ee 100644 --- a/src/cpp/common/call.cc +++ b/src/cpp/common/call.cc @@ -42,6 +42,36 @@ namespace grpc { +void FillMetadataMap(grpc_metadata_array* arr, + std::multimap<grpc::string, grpc::string>* metadata) { + for (size_t i = 0; i < arr->count; i++) { + // TODO(yangg) handle duplicates? + metadata->insert(std::pair<grpc::string, grpc::string>( + arr->metadata[i].key, + grpc::string(arr->metadata[i].value, arr->metadata[i].value_length))); + } + grpc_metadata_array_destroy(arr); + grpc_metadata_array_init(arr); +} + +// TODO(yangg) if the map is changed before we send, the pointers will be a +// mess. Make sure it does not happen. +grpc_metadata* FillMetadataArray( + const std::multimap<grpc::string, grpc::string>& metadata) { + if (metadata.empty()) { + return nullptr; + } + grpc_metadata* metadata_array = + (grpc_metadata*)gpr_malloc(metadata.size() * sizeof(grpc_metadata)); + size_t i = 0; + for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { + metadata_array[i].key = iter->first.c_str(); + metadata_array[i].value = iter->second.c_str(); + metadata_array[i].value_length = iter->second.size(); + } + return metadata_array; +} + #if 0 CallOpBuffer::CallOpBuffer() : return_tag_(this), @@ -147,17 +177,6 @@ grpc_metadata* FillMetadataArray( return metadata_array; } -void FillMetadataMap(grpc_metadata_array* arr, - std::multimap<grpc::string, grpc::string>* metadata) { - for (size_t i = 0; i < arr->count; i++) { - // TODO(yangg) handle duplicates? - metadata->insert(std::pair<grpc::string, grpc::string>( - arr->metadata[i].key, - grpc::string(arr->metadata[i].value, arr->metadata[i].value_length))); - } - grpc_metadata_array_destroy(arr); - grpc_metadata_array_init(arr); -} } // namespace void CallOpBuffer::AddSendInitialMetadata( |