[#23] Client: Refactoring to optimize memory usage
Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
parent
1a02ac2ae7
commit
6562aa27a5
141 changed files with 1722 additions and 896 deletions
|
@ -6,13 +6,12 @@ using FrostFS.Object;
|
|||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
internal class ObjectTools
|
||||
{
|
||||
internal static ObjectId CalculateObjectId(ObjectHeader header, Context ctx)
|
||||
internal static FrostFsObjectId CalculateObjectId(FrostFsObjectHeader header, Context ctx)
|
||||
{
|
||||
var grpcHeader = CreateHeader(header, [], ctx);
|
||||
|
||||
|
@ -24,10 +23,10 @@ internal class ObjectTools
|
|||
|
||||
internal static Object.Object CreateObject(FrostFsObject @object, Context ctx)
|
||||
{
|
||||
@object.Header.OwnerId = ctx.OwnerId;
|
||||
@object.Header.Version = ctx.Version;
|
||||
@object.Header.OwnerId ??= ctx.OwnerId;
|
||||
@object.Header.Version ??= ctx.Version;
|
||||
|
||||
var grpcHeader = @object.Header.ToMessage();
|
||||
var grpcHeader = @object.Header.GetHeader();
|
||||
|
||||
grpcHeader.PayloadLength = (ulong)@object.Payload.Length;
|
||||
grpcHeader.PayloadHash = Sha256Checksum(@object.Payload);
|
||||
|
@ -47,18 +46,21 @@ internal class ObjectTools
|
|||
|
||||
obj.Signature = new Refs.Signature
|
||||
{
|
||||
Key = ctx.PublicKeyCache,
|
||||
Key = ctx.GetPublicKeyCache(),
|
||||
Sign = ByteString.CopyFrom(ctx.Key.SignData(obj.ObjectId.ToByteArray())),
|
||||
};
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
internal static void SetSplitValues(Header grpcHeader, ModelsV2.Split split, Context ctx)
|
||||
internal static void SetSplitValues(Header grpcHeader, FrostFsSplit split, Context ctx)
|
||||
{
|
||||
if (split == null)
|
||||
return;
|
||||
|
||||
grpcHeader.Split = new Header.Types.Split
|
||||
{
|
||||
SplitId = split.SplitId != null ? ByteString.CopyFrom(split.SplitId.ToBinary()) : null
|
||||
SplitId = split.SplitId?.GetSplitId()
|
||||
};
|
||||
|
||||
if (split.Children != null && split.Children.Count != 0)
|
||||
|
@ -72,7 +74,7 @@ internal class ObjectTools
|
|||
grpcHeader.Split.ParentHeader = grpcParentHeader;
|
||||
grpcHeader.Split.ParentSignature = new Refs.Signature
|
||||
{
|
||||
Key = ctx.PublicKeyCache,
|
||||
Key = ctx.GetPublicKeyCache(),
|
||||
Sign = ByteString.CopyFrom(ctx.Key.SignData(grpcHeader.Split.Parent.ToByteArray())),
|
||||
};
|
||||
|
||||
|
@ -82,13 +84,13 @@ internal class ObjectTools
|
|||
grpcHeader.Split.Previous = split.Previous?.ToMessage();
|
||||
}
|
||||
|
||||
internal static Header CreateHeader(ObjectHeader header, byte[]? payload, Context ctx)
|
||||
internal static Header CreateHeader(FrostFsObjectHeader header, byte[]? payload, Context ctx)
|
||||
{
|
||||
var grpcHeader = header.ToMessage();
|
||||
|
||||
grpcHeader.OwnerId = ctx.OwnerId.ToMessage();
|
||||
grpcHeader.Version = ctx.Version.ToMessage();
|
||||
header.OwnerId ??= ctx.OwnerId;
|
||||
header.Version ??= ctx.Version;
|
||||
|
||||
var grpcHeader = header.GetHeader();
|
||||
|
||||
if (payload != null) // && payload.Length > 0
|
||||
grpcHeader.PayloadHash = Sha256Checksum(payload);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue