[#28] Client: Use external GRPC Channnel

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2024-12-06 09:01:33 +03:00
parent 9bb7b5eff8
commit c9418a1894
27 changed files with 520 additions and 438 deletions

View file

@ -0,0 +1,68 @@
using System;
using System.Threading.Tasks;
using FrostFS.Object;
using FrostFS.SDK.Client.Interfaces;
using Google.Protobuf;
namespace FrostFS.SDK.Client
{
internal sealed class ObjectWriter : IObjectWriter
{
private readonly ClientContext ctx;
private readonly PrmObjectPutBase args;
private readonly ObjectStreamer<PutRequest, PutResponse> streamer;
private bool disposedValue;
internal ObjectWriter(ClientContext ctx, PrmObjectPutBase args, ObjectStreamer<PutRequest, PutResponse> streamer)
{
this.ctx = ctx;
this.args = args;
this.streamer = streamer;
}
public async Task WriteAsync(ReadOnlyMemory<byte> memory)
{
var chunkRequest = new PutRequest
{
Body = new PutRequest.Types.Body
{
Chunk = UnsafeByteOperations.UnsafeWrap(memory)
}
};
chunkRequest.Sign(this.ctx.Key.ECDsaKey);
await streamer.Write(chunkRequest).ConfigureAwait(false);
}
public async Task<FrostFsObjectId> CompleteAsync()
{
var response = await streamer.Close().ConfigureAwait(false);
Verifier.CheckResponse(response);
return FrostFsObjectId.FromHash(response.Body.ObjectId.Value.Span);
}
private void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
streamer.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}