Initial SDK structure #1

Merged
i.pchelintsev merged 18 commits from i.pchelintsev/frostfs-sdk-csharp:master into master 2024-09-04 19:51:24 +00:00
2 changed files with 55 additions and 4 deletions
Showing only changes of commit 9aa93d123d - Show all commits

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()
};
}
}
}

View file

@ -2,15 +2,33 @@ using FrostFS.SDK.ModelsV2.Enums;
namespace FrostFS.SDK.ModelsV2;
public class ObjectAttribute
{
public string Key { get; set; }
public string Value { get; set; }
public ObjectAttribute(string key, string value)
{
Key = key;
Value = value;
}
}
public class ObjectHeader
{
public ObjectAttribute[] Attributes { get; set; }
public ContainerId ContainerId { get; set; }
public long Size { get; set; }
public ObjectType ObjectType { get; set; }
public Version Version { get; set; }
public ObjectHeader(ContainerId containerId, ObjectType type = ObjectType.Regular)
public ObjectHeader(
ContainerId containerId,
ObjectType type = ObjectType.Regular,
params ObjectAttribute[] attributes
)
{
Attributes = attributes;
ContainerId = containerId;
ObjectType = type;
}