internal static async Task <uint?> GetCid(this IConnection connection, string name, ITypeTranscoder transcoder) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using var getCid = new GetCid { Key = name, Transcoder = transcoder, Opaque = SequenceGenerator.GetNext(), Content = null, Completed = s => { completionSource.TrySetResult(s.ExtractData()); return(completionSource.Task); } }; await getCid.SendAsync(connection).ConfigureAwait(false); var gitCidBytes = await completionSource.Task.ConfigureAwait(false); await getCid.ReadAsync(gitCidBytes).ConfigureAwait(false); var resultWithValue = getCid.GetResultWithValue(); return(resultWithValue.Content); }
public void Test_GetWithValue() { var packet = new byte[] { 129, 187, 0, 0, 12, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 0, 0, 0, 34 }; var response = MemoryPool <byte> .Shared.RentAndSlice(packet.Length); packet.AsMemory(0, packet.Length).CopyTo(response.Memory); var op = new GetCid(); op.ReadAsync(response); var result = op.GetResultWithValue(); Assert.True(result.Content.HasValue); Assert.Equal(85u, result.Content.Value); }