From b9183153211d109ba57598812ee8d90a12236443 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 30 Jul 2019 16:16:56 -0700 Subject: [PATCH] a bit of refactor --- src/csharp/Grpc.Core/Internal/AsyncCallBase.cs | 2 +- src/csharp/Grpc.Core/Internal/SliceBufferSafeHandle.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs index 23cb5ccffc7..b26b7921955 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs @@ -220,7 +220,7 @@ namespace Grpc.Core.Internal { context = DefaultSerializationContext.GetInitializedThreadLocal(); serializer(msg, context); - return context.GetPayload().GetPayload(); + return context.GetPayload().ToByteArray(); } finally { diff --git a/src/csharp/Grpc.Core/Internal/SliceBufferSafeHandle.cs b/src/csharp/Grpc.Core/Internal/SliceBufferSafeHandle.cs index ef9e7fbce37..5b540c69d44 100644 --- a/src/csharp/Grpc.Core/Internal/SliceBufferSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/SliceBufferSafeHandle.cs @@ -79,7 +79,9 @@ namespace Grpc.Core.Internal AdjustTailSpace(0); } - public byte[] GetPayload() + // copies the content of the slice buffer to a newly allocated byte array + // due to its overhead, this method should only be used for testing. + public byte[] ToByteArray() { ulong sliceCount = Native.grpcsharp_slice_buffer_slice_count(this).ToUInt64(); @@ -102,7 +104,6 @@ namespace Grpc.Core.Internal GrpcPreconditions.CheckState(totalLen == offset); return result; } - // TODO: converting contents to byte[] // Gets data of server_rpc_new completion. private void AdjustTailSpace(int requestedSize) @@ -112,7 +113,6 @@ namespace Grpc.Core.Internal tailSpacePtr = Native.grpcsharp_slice_buffer_adjust_tail_space(this, tailSpaceLen, requestedTailSpaceLen); tailSpaceLen = requestedTailSpaceLen; } - protected override bool ReleaseHandle() { Native.grpcsharp_slice_buffer_destroy(handle);