File tree 1 file changed +15
-2
lines changed
third-party/thrift/src/thrift/lib/cpp2/transport/rocket/framing/parser
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ class AlignedParserStrategy {
111
111
std::unique_ptr<folly::IOBuf> createDataBuffer ();
112
112
std::unique_ptr<folly::IOBuf> createRequestResponseDataBuffer ();
113
113
std::unique_ptr<folly::IOBuf> createPayloadDataBuffer ();
114
+ std::unique_ptr<folly::IOBuf> createAlignedBuffer (size_t size);
114
115
115
116
void handleAwaitingHeader (size_t len);
116
117
@@ -134,16 +135,28 @@ std::unique_ptr<folly::IOBuf> AlignedParserStrategy<T>::createHeaderBuffer() {
134
135
return folly::IOBuf::createCombined (kHeaderBufferLength );
135
136
}
136
137
138
+ template <typename T>
139
+ std::unique_ptr<folly::IOBuf> AlignedParserStrategy<T>::createAlignedBuffer(
140
+ const size_t size) {
141
+ // We need to allocate an extra byte for the IOBuf to be able to
142
+ // make sure the first field in a binary encoded thrift struct is
143
+ // aligned. There are 7 bytes between the start of the first field and
144
+ // the start of the struct.
145
+ auto buffer = folly::IOBuf::createSeparate (size + 1 );
146
+ buffer->advance (1 );
147
+ return buffer;
148
+ }
149
+
137
150
template <typename T>
138
151
std::unique_ptr<folly::IOBuf>
139
152
AlignedParserStrategy<T>::createRequestResponseDataBuffer() {
140
- return folly::IOBuf::createCombined (remainingData_);
153
+ return createAlignedBuffer (remainingData_);
141
154
}
142
155
143
156
template <typename T>
144
157
std::unique_ptr<folly::IOBuf>
145
158
AlignedParserStrategy<T>::createPayloadDataBuffer() {
146
- return folly::IOBuf::createCombined (remainingData_);
159
+ return createAlignedBuffer (remainingData_);
147
160
}
148
161
149
162
template <typename T>
You can’t perform that action at this time.
0 commit comments