Commit e442ff4
Use IOBufPtr for binary payload fields
Summary:
The bare "binary" type in Thrift IDL maps to std::string in the generated C++
code. On the deserialization path this hits the std::string overload of
apache::thrift::detail::readStringBody (Protocol.h:435), which calls
folly::io::Cursor::pullAtMost into the string's storage - a memcpy of the
full payload out of the receive IOBuf chain.
Switch every bare binary payload field in StressTest.thrift to the existing
IOBufPtr typedef, which is annotated with
`cpp.Type{name = "std::unique_ptr<folly::IOBuf>"}`. The generated reader then
dispatches to the IOBuf overload of readBinary, which clones buffer references
via Cursor::clone - refcount bumps, no payload memcpy.
This is a wire-compatible change (still serialized as a binary field) but is a
source-incompatible C++ API change: handlers/clients now see
`std::unique_ptr<folly::IOBuf>` instead of std::string. The stoptls_payload
fields already used IOBufPtr, so handler code already knows how to consume
the IOBuf form.
Differential Revision: D101410011
fbshipit-source-id: 94c337e83b83584acbee37fc31f875276058e62e1 parent b665d88 commit e442ff4
2 files changed
Lines changed: 10 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| |||
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
309 | 312 | | |
310 | 313 | | |
311 | 314 | | |
| |||
316 | 319 | | |
317 | 320 | | |
318 | 321 | | |
319 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
320 | 326 | | |
321 | 327 | | |
322 | 328 | | |
| |||
0 commit comments