aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/util/byte_buffer_proto_helper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/util/byte_buffer_proto_helper.cc')
-rw-r--r--test/cpp/util/byte_buffer_proto_helper.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/cpp/util/byte_buffer_proto_helper.cc b/test/cpp/util/byte_buffer_proto_helper.cc
index bb5162f86e..37098955d4 100644
--- a/test/cpp/util/byte_buffer_proto_helper.cc
+++ b/test/cpp/util/byte_buffer_proto_helper.cc
@@ -40,5 +40,18 @@ std::unique_ptr<ByteBuffer> SerializeToByteBuffer(
return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1));
}
+bool SerializeToByteBufferInPlace(grpc::protobuf::Message* message,
+ ByteBuffer* buffer) {
+ grpc::string buf;
+ if (!message->SerializeToString(&buf)) {
+ return false;
+ }
+ buffer->Clear();
+ Slice slice(buf);
+ ByteBuffer tmp(&slice, 1);
+ buffer->Swap(&tmp);
+ return true;
+}
+
} // namespace testing
} // namespace grpc