| 223 | // flatbuffers-encoded region and wraps it in a `Message<T>` to handle buffer |
| 224 | // ownership. |
| 225 | template<class T> Message<T> GetMessage() { |
| 226 | auto buf_data = buf_.scratch_data(); // pointer to memory |
| 227 | auto buf_size = buf_.capacity(); // size of memory |
| 228 | auto msg_data = buf_.data(); // pointer to msg |
| 229 | auto msg_size = buf_.size(); // size of msg |
| 230 | // Do some sanity checks on data/size |
| 231 | FLATBUFFERS_ASSERT(msg_data); |
| 232 | FLATBUFFERS_ASSERT(msg_size); |
| 233 | FLATBUFFERS_ASSERT(msg_data >= buf_data); |
| 234 | FLATBUFFERS_ASSERT(msg_data + msg_size <= buf_data + buf_size); |
| 235 | // Calculate offsets from the buffer start |
| 236 | auto begin = msg_data - buf_data; |
| 237 | auto end = begin + msg_size; |
| 238 | // Get the slice we are working with (no refcount change) |
| 239 | ::grpc::Slice slice = slice_allocator_.get_slice(buf_data, buf_size); |
| 240 | // Extract a subslice of the existing slice (increment refcount) |
| 241 | ::grpc::Slice subslice = slice.sub(begin, end); |
| 242 | // Wrap the subslice in a `Message<T>`, but don't increment refcount |
| 243 | Message<T> msg(subslice); |
| 244 | return msg; |
| 245 | } |
| 246 | |
| 247 | template<class T> Message<T> ReleaseMessage() { |
| 248 | Message<T> msg = GetMessage<T>(); |
no test coverage detected