Return a ByteBuffer that contains str split up into num_slices slices.
| 33 | |
| 34 | // Return a ByteBuffer that contains str split up into num_slices slices. |
| 35 | grpc::ByteBuffer MakeBuffer(const string& str, int num_slices) { |
| 36 | // Convert to a ByteBuffer. |
| 37 | std::vector<::grpc::Slice> slices; |
| 38 | const size_t per_slice = (str.size() + num_slices - 1) / num_slices; |
| 39 | for (size_t pos = 0; pos < str.size();) { |
| 40 | const size_t n = std::min(str.size() - pos, per_slice); |
| 41 | slices.emplace_back(&str[pos], n); |
| 42 | pos += n; |
| 43 | } |
| 44 | if (slices.empty()) { |
| 45 | slices.emplace_back(); |
| 46 | } |
| 47 | return ::grpc::ByteBuffer(&slices[0], slices.size()); |
| 48 | } |
| 49 | |
| 50 | // Make a proto with approximately the specified length. |
| 51 | CleanupAllRequest MakeProto(int size) { |
no test coverage detected