[#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
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using FrostFS.Object;
|
||||
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
namespace FrostFS.SDK;
|
||||
|
||||
public class FrostFsObjectHeader(
|
||||
FrostFsContainerId containerId,
|
||||
FrostFsObjectType type = FrostFsObjectType.Regular,
|
||||
FrostFsAttribute[]? attributes = null,
|
||||
FrostFsSplit? split = null,
|
||||
FrostFsOwner? owner = null,
|
||||
FrostFsVersion? version = null)
|
||||
{
|
||||
private Header header;
|
||||
private Container.Container.Types.Attribute[]? grpsAttributes;
|
||||
|
||||
public List<FrostFsAttribute> Attributes { get; internal set; } = attributes != null ? [.. attributes] : [];
|
||||
|
||||
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||
|
||||
public ulong PayloadLength { get; set; }
|
||||
|
||||
public byte[]? PayloadCheckSum { get; set; }
|
||||
|
||||
public FrostFsObjectType ObjectType { get; } = type;
|
||||
|
||||
public FrostFsOwner? OwnerId { get; internal set; } = owner;
|
||||
|
||||
public FrostFsVersion? Version { get; internal set; } = version;
|
||||
|
||||
public FrostFsSplit? Split { get; internal set; } = split;
|
||||
|
||||
internal Container.Container.Types.Attribute[]? GetGrpsAttributes()
|
||||
{
|
||||
grpsAttributes ??= Attributes?
|
||||
.Select(a => new Container.Container.Types.Attribute { Key = a.Key, Value = a.Value })
|
||||
.ToArray();
|
||||
|
||||
return grpsAttributes;
|
||||
}
|
||||
|
||||
public Header GetHeader()
|
||||
{
|
||||
if (header == null)
|
||||
{
|
||||
var objTypeName = ObjectType switch
|
||||
{
|
||||
FrostFsObjectType.Regular => Object.ObjectType.Regular,
|
||||
FrostFsObjectType.Lock => Object.ObjectType.Lock,
|
||||
FrostFsObjectType.Tombstone => Object.ObjectType.Tombstone,
|
||||
_ => throw new ArgumentException($"Unknown ObjectType. Value: '{ObjectType}'.")
|
||||
};
|
||||
|
||||
this.header = new Header
|
||||
{
|
||||
OwnerId = OwnerId?.ToMessage(),
|
||||
Version = Version?.ToMessage(),
|
||||
ContainerId = ContainerId.ToMessage(),
|
||||
ObjectType = objTypeName,
|
||||
PayloadLength = PayloadLength
|
||||
};
|
||||
|
||||
foreach (var attribute in Attributes)
|
||||
{
|
||||
this.header.Attributes.Add(attribute.ToMessage());
|
||||
}
|
||||
|
||||
var split = Split;
|
||||
if (split != null)
|
||||
{
|
||||
this.header.Split = new Header.Types.Split
|
||||
{
|
||||
SplitId = split!.SplitId != null ? split.SplitId.GetSplitId() : null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return this.header;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue