Thrift: Update the interface for TTransport's "borrow" method.
Summary:
I don't know what I was thinking when I first wrote this.
It makes sense that the transport might not want to allocate its own memory,
so the protocol is expected to provide a buffer for the data.
However, if the transport already has the data buffered,
there is no need to memcpy it; it can just return a pointer into its buffer.
The new interface still requires the protocol to provide a buffer,
but allows the transport to return a pointer to an interal buffer.
In addition, I made len a pass-by-pointer parameter so that
the transport can return more than the requested data if it has it
available in its buffers.
Reviewed By: mcslee
Test Plan: Ran the DenseProtocol test and the Zlib test.
Revert Plan: ok
Other Notes:
Also got this reviewed by Chad Walters from Powerset.
Ben Maurer suggested making len a reference parameter.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665454 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/protocol/TDenseProtocol.cpp b/lib/cpp/src/protocol/TDenseProtocol.cpp
index e79d4f1..55f3902 100644
--- a/lib/cpp/src/protocol/TDenseProtocol.cpp
+++ b/lib/cpp/src/protocol/TDenseProtocol.cpp
@@ -180,12 +180,13 @@
uint32_t used = 0;
uint64_t val = 0;
uint8_t buf[10]; // 64 bits / (7 bits/byte) = 10 bytes.
- bool borrowed = trans_->borrow(buf, sizeof(buf));
+ uint32_t buf_size = sizeof(buf);
+ const uint8_t* borrowed = trans_->borrow(buf, &buf_size);
// Fast path. TODO(dreiss): Make it faster.
- if (borrowed) {
+ if (borrowed != NULL) {
while (true) {
- uint8_t byte = buf[used];
+ uint8_t byte = borrowed[used];
used++;
val = (val << 7) | (byte & 0x7f);
if (!(byte & 0x80)) {