63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
using FrostFS.Object;
|
|
using FrostFS.SDK.Cryptography;
|
|
|
|
namespace FrostFS.SDK.Client.Mappers.GRPC;
|
|
|
|
public static class ObjectHeaderMapper
|
|
{
|
|
public static FrostFsObjectHeader ToModel(this Header header)
|
|
{
|
|
if (header is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(header));
|
|
}
|
|
|
|
var objTypeName = header.ObjectType switch
|
|
{
|
|
ObjectType.Regular => FrostFsObjectType.Regular,
|
|
ObjectType.Lock => FrostFsObjectType.Lock,
|
|
ObjectType.Tombstone => FrostFsObjectType.Tombstone,
|
|
_ => throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.")
|
|
};
|
|
|
|
FrostFsSplit? split = header!.Split != null
|
|
? header.Split.ToModel()
|
|
: null;
|
|
|
|
var model = new FrostFsObjectHeader(
|
|
new FrostFsContainerId(Base58.Encode(header.ContainerId.Value.Span)),
|
|
objTypeName,
|
|
[.. header.Attributes.Select(attribute => attribute.ToModel())],
|
|
split,
|
|
header.OwnerId.ToModel(),
|
|
header.Version.ToModel())
|
|
{
|
|
PayloadLength = header.PayloadLength,
|
|
};
|
|
|
|
return model;
|
|
}
|
|
|
|
public static FrostFsSplit ToModel(this Header.Types.Split split)
|
|
{
|
|
if (split is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(split));
|
|
}
|
|
|
|
var children = split!.Children.Count != 0
|
|
? new ReadOnlyCollection<FrostFsObjectId>([.. split.Children.Select(x => x.ToModel())])
|
|
: null;
|
|
|
|
return new FrostFsSplit(new SplitId(split.SplitId.ToUuid()),
|
|
split.Previous?.ToModel(),
|
|
split.Parent?.ToModel(),
|
|
split.ParentHeader?.ToModel(),
|
|
null,
|
|
children);
|
|
}
|
|
}
|