[#1] Add object attributes

Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
Ivan Pchelintsev 2024-05-16 14:01:38 +03:00
parent 6b8f8cbd4c
commit 9aa93d123d
2 changed files with 55 additions and 4 deletions

View file

@ -3,6 +3,23 @@ using FrostFS.SDK.ModelsV2;
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
public static class ObjectAttributeMapper
{
public static Header.Types.Attribute ToGrpcMessage(this ObjectAttribute attribute)
{
return new Header.Types.Attribute
{
Key = attribute.Key,
Value = attribute.Value
};
}
public static ObjectAttribute ToModel(this Header.Types.Attribute attribute)
{
return new ObjectAttribute(attribute.Key, attribute.Value);
}
}
public static class ObjectHeadMapper
{
public static Header ToGrpcMessage(this ObjectHeader header)
@ -12,11 +29,19 @@ public static class ObjectHeadMapper
{
throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.");
}
return new Header
var head = new Header
{
Attributes = { },
ContainerId = header.ContainerId.ToGrpcMessage(),
ObjectType = Enum.Parse<ObjectType>(objTypeName)
};
foreach (var attribute in header.Attributes)
{
head.Attributes.Add(attribute.ToGrpcMessage());
}
return head;
}
public static ObjectHeader ToModel(this Header header)
@ -26,13 +51,21 @@ public static class ObjectHeadMapper
{
throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.");
}
var attributes = new List<ObjectAttribute>();
foreach (var attribute in header.Attributes)
{
attributes.Add(attribute.ToModel());
}
return new ObjectHeader(
ContainerId.FromHash(header.ContainerId.Value.ToByteArray()),
Enum.Parse<ModelsV2.Enums.ObjectType>(objTypeName)
Enum.Parse<ModelsV2.Enums.ObjectType>(objTypeName),
attributes.ToArray()
)
{
Size = (long)header.PayloadLength,
Version = header.Version.ToModel()
};
}
}
}