a bit of refactor

pull/19792/head
Jan Tattermusch 5 years ago
parent 1154c2d17e
commit b918315321
  1. 2
      src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
  2. 6
      src/csharp/Grpc.Core/Internal/SliceBufferSafeHandle.cs

@ -220,7 +220,7 @@ namespace Grpc.Core.Internal
{ {
context = DefaultSerializationContext.GetInitializedThreadLocal(); context = DefaultSerializationContext.GetInitializedThreadLocal();
serializer(msg, context); serializer(msg, context);
return context.GetPayload().GetPayload(); return context.GetPayload().ToByteArray();
} }
finally finally
{ {

@ -79,7 +79,9 @@ namespace Grpc.Core.Internal
AdjustTailSpace(0); 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(); ulong sliceCount = Native.grpcsharp_slice_buffer_slice_count(this).ToUInt64();
@ -102,7 +104,6 @@ namespace Grpc.Core.Internal
GrpcPreconditions.CheckState(totalLen == offset); GrpcPreconditions.CheckState(totalLen == offset);
return result; return result;
} }
// TODO: converting contents to byte[]
// Gets data of server_rpc_new completion. // Gets data of server_rpc_new completion.
private void AdjustTailSpace(int requestedSize) private void AdjustTailSpace(int requestedSize)
@ -112,7 +113,6 @@ namespace Grpc.Core.Internal
tailSpacePtr = Native.grpcsharp_slice_buffer_adjust_tail_space(this, tailSpaceLen, requestedTailSpaceLen); tailSpacePtr = Native.grpcsharp_slice_buffer_adjust_tail_space(this, tailSpaceLen, requestedTailSpaceLen);
tailSpaceLen = requestedTailSpaceLen; tailSpaceLen = requestedTailSpaceLen;
} }
protected override bool ReleaseHandle() protected override bool ReleaseHandle()
{ {
Native.grpcsharp_slice_buffer_destroy(handle); Native.grpcsharp_slice_buffer_destroy(handle);

Loading…
Cancel
Save