diff options
author | 2017-09-14 17:55:42 +0200 | |
---|---|---|
committer | 2017-09-14 17:55:42 +0200 | |
commit | 5432dd887430984713f9fc3ad595c85e995d6451 (patch) | |
tree | 8ef07a15e7defb9085584b74fdcbbeb8646b4ae8 /src/cpp/util | |
parent | 804bd6aa6ba0a6ff95ba2927b79aeb81dc02fe29 (diff) |
Revert "Allow SerializationTraits to use grpc::ByteBuffer rather than only grpc_byte_buffer"
Diffstat (limited to 'src/cpp/util')
-rw-r--r-- | src/cpp/util/byte_buffer_cc.cc | 37 | ||||
-rw-r--r-- | src/cpp/util/slice_cc.cc | 2 |
2 files changed, 14 insertions, 25 deletions
diff --git a/src/cpp/util/byte_buffer_cc.cc b/src/cpp/util/byte_buffer_cc.cc index 1ebe22b6a4..b1ff25252a 100644 --- a/src/cpp/util/byte_buffer_cc.cc +++ b/src/cpp/util/byte_buffer_cc.cc @@ -16,15 +16,11 @@ * */ -#include <grpc++/impl/grpc_library.h> #include <grpc++/support/byte_buffer.h> -#include <grpc/byte_buffer.h> #include <grpc/byte_buffer_reader.h> namespace grpc { -static internal::GrpcLibraryInitializer g_gli_initializer; - ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) { // The following assertions check that the representation of a grpc::Slice is // identical to that of a grpc_slice: it has a grpc_slice field, and nothing @@ -33,7 +29,6 @@ ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) { "Slice must have same representation as grpc_slice"); static_assert(sizeof(Slice) == sizeof(grpc_slice), "Slice must have same representation as grpc_slice"); - g_gli_initializer.summon(); // Make sure that initializer linked in // The const_cast is legal if grpc_raw_byte_buffer_create() does no more // than its advertised side effect of increasing the reference count of the // slices it processes, and such an increase does not affect the semantics @@ -42,6 +37,19 @@ ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) { reinterpret_cast<grpc_slice*>(const_cast<Slice*>(slices)), nslices); } +ByteBuffer::~ByteBuffer() { + if (buffer_) { + grpc_byte_buffer_destroy(buffer_); + } +} + +void ByteBuffer::Clear() { + if (buffer_) { + grpc_byte_buffer_destroy(buffer_); + buffer_ = nullptr; + } +} + Status ByteBuffer::Dump(std::vector<Slice>* slices) const { slices->clear(); if (!buffer_) { @@ -72,9 +80,7 @@ ByteBuffer::ByteBuffer(const ByteBuffer& buf) : buffer_(grpc_byte_buffer_copy(buf.buffer_)) {} ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) { - if (this != &buf) { - Clear(); // first remove existing data - } + Clear(); // first remove existing data if (buf.buffer_) { buffer_ = grpc_byte_buffer_copy(buf.buffer_); // then copy } @@ -87,19 +93,4 @@ void ByteBuffer::Swap(ByteBuffer* other) { buffer_ = tmp; } -ByteBuffer::operator grpc_byte_buffer*() { - // The following assertions check that the representation of a ByteBuffer is - // identical to grpc_byte_buffer*: it has a grpc_byte_buffer* field, - // and nothing else. - static_assert(std::is_same<decltype(buffer_), grpc_byte_buffer*>::value, - "ByteBuffer must have same representation as " - "grpc_byte_buffer*"); - static_assert(sizeof(ByteBuffer) == sizeof(grpc_byte_buffer*), - "ByteBuffer must have same representation as " - "grpc_byte_buffer*"); - return buffer_; -} - -ByteBuffer::operator const grpc_byte_buffer*() const { return buffer_; } - } // namespace grpc diff --git a/src/cpp/util/slice_cc.cc b/src/cpp/util/slice_cc.cc index 3ae17e8052..486d0cdf0e 100644 --- a/src/cpp/util/slice_cc.cc +++ b/src/cpp/util/slice_cc.cc @@ -50,6 +50,4 @@ Slice::Slice(void* buf, size_t len, void (*destroy)(void*), void* user_data) Slice::Slice(void* buf, size_t len, void (*destroy)(void*, size_t)) : slice_(grpc_slice_new_with_len(buf, len, destroy)) {} -grpc_slice Slice::c_slice() const { return grpc_slice_ref(slice_); } - } // namespace grpc |