|
|
@ -37,12 +37,19 @@ |
|
|
|
namespace grpc { |
|
|
|
namespace grpc { |
|
|
|
|
|
|
|
|
|
|
|
ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) { |
|
|
|
ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) { |
|
|
|
// TODO(yangg) maybe expose some core API to simplify this
|
|
|
|
// The following assertions check that the representation of a grpc::Slice is
|
|
|
|
std::vector<gpr_slice> c_slices(nslices); |
|
|
|
// identical to that of a gpr_slice: it has a gpr_slice field, and nothing
|
|
|
|
for (size_t i = 0; i < nslices; i++) { |
|
|
|
// else.
|
|
|
|
c_slices[i] = slices[i].slice_; |
|
|
|
static_assert(std::is_same<decltype(slices[0].slice_), gpr_slice>::value, |
|
|
|
} |
|
|
|
"Slice must have same representation as gpr_slice"); |
|
|
|
buffer_ = grpc_raw_byte_buffer_create(c_slices.data(), nslices); |
|
|
|
static_assert(sizeof(Slice) == sizeof(gpr_slice), |
|
|
|
|
|
|
|
"Slice must have same representation as gpr_slice"); |
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// seen by the caller of this constructor.
|
|
|
|
|
|
|
|
buffer_ = grpc_raw_byte_buffer_create( |
|
|
|
|
|
|
|
reinterpret_cast<gpr_slice*>(const_cast<Slice*>(slices)), nslices); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ByteBuffer::~ByteBuffer() { |
|
|
|
ByteBuffer::~ByteBuffer() { |
|
|
@ -95,4 +102,10 @@ ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) { |
|
|
|
return *this; |
|
|
|
return *this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ByteBuffer::Swap(ByteBuffer* other) { |
|
|
|
|
|
|
|
grpc_byte_buffer* tmp = other->buffer_; |
|
|
|
|
|
|
|
other->buffer_ = this->buffer_; |
|
|
|
|
|
|
|
this->buffer_ = tmp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace grpc
|
|
|
|
} // namespace grpc
|
|
|
|