90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
using FrostFS.Object;
|
|
|
|
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
|
|
|
namespace FrostFS.SDK;
|
|
|
|
public class FrostFsObjectHeader(
|
|
FrostFsContainerId containerId,
|
|
FrostFsObjectType type = FrostFsObjectType.Regular,
|
|
FrostFsAttributePair[]? attributes = null,
|
|
FrostFsSplit? split = null,
|
|
FrostFsOwner? owner = null,
|
|
FrostFsVersion? version = null)
|
|
{
|
|
private Header? header;
|
|
private Container.Container.Types.Attribute[]? grpsAttributes;
|
|
|
|
public ReadOnlyCollection<FrostFsAttributePair>? Attributes { get; internal set; } =
|
|
attributes == null ? null :
|
|
new ReadOnlyCollection<FrostFsAttributePair>(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
|
|
};
|
|
|
|
if (Attributes != null)
|
|
{
|
|
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;
|
|
}
|
|
}
|