[#4] infrastructure and sample Client Cut
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
0c4723c705
commit
545e647d7b
22 changed files with 717 additions and 193 deletions
|
@ -1,8 +1,9 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using FrostFS.Object;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
using Google.Protobuf;
|
||||
using MatchType = FrostFS.Object.MatchType;
|
||||
using ObjectType = FrostFS.Object.ObjectType;
|
||||
|
||||
|
@ -29,11 +30,20 @@ public static class ObjectFilterMapper
|
|||
{
|
||||
public static SearchRequest.Types.Body.Types.Filter ToGrpcMessage(this ObjectFilter filter)
|
||||
{
|
||||
var objMatchTypeName = Enum.GetName(typeof(MatchType), filter.MatchType)
|
||||
?? throw new ArgumentException($"Unknown MatchType. Value: '{filter.MatchType}'.");
|
||||
var objMatchTypeName = filter.MatchType switch
|
||||
{
|
||||
ModelsV2.Enums.ObjectMatchType.Unspecified => MatchType.Unspecified,
|
||||
ModelsV2.Enums.ObjectMatchType.Equals => MatchType.StringEqual,
|
||||
ModelsV2.Enums.ObjectMatchType.NotEquals => MatchType.StringNotEqual,
|
||||
ModelsV2.Enums.ObjectMatchType.KeyAbsent => MatchType.NotPresent,
|
||||
ModelsV2.Enums.ObjectMatchType.StartsWith => MatchType.CommonPrefix,
|
||||
|
||||
_ => throw new ArgumentException($"Unknown MatchType. Value: '{filter.MatchType}'.")
|
||||
};
|
||||
|
||||
return new SearchRequest.Types.Body.Types.Filter
|
||||
{
|
||||
MatchType = (MatchType)Enum.Parse(typeof(MatchType), objMatchTypeName),
|
||||
MatchType = objMatchTypeName,
|
||||
Key = filter.Key,
|
||||
Value = filter.Value
|
||||
};
|
||||
|
@ -44,13 +54,19 @@ public static class ObjectHeaderMapper
|
|||
{
|
||||
public static Header ToGrpcMessage(this ObjectHeader header)
|
||||
{
|
||||
var objTypeName = Enum.GetName(typeof(ObjectType), header.ObjectType)
|
||||
?? throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.");
|
||||
var head = new Header
|
||||
var objTypeName = header.ObjectType switch
|
||||
{
|
||||
Attributes = { },
|
||||
ModelsV2.Enums.ObjectType.Regular => ObjectType.Regular,
|
||||
ModelsV2.Enums.ObjectType.Lock => ObjectType.Lock,
|
||||
ModelsV2.Enums.ObjectType.Tombstone => ObjectType.Tombstone,
|
||||
_ => throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.")
|
||||
};
|
||||
|
||||
var head = new Header
|
||||
{
|
||||
ContainerId = header.ContainerId.ToGrpcMessage(),
|
||||
ObjectType = (ObjectType)Enum.Parse(typeof(ObjectType), objTypeName)
|
||||
ObjectType = objTypeName,
|
||||
PayloadLength = header.PayloadLength
|
||||
};
|
||||
|
||||
foreach (var attribute in header.Attributes)
|
||||
|
@ -58,20 +74,42 @@ public static class ObjectHeaderMapper
|
|||
head.Attributes.Add(attribute.ToGrpcMessage());
|
||||
}
|
||||
|
||||
var split = header.Split;
|
||||
if (split != null)
|
||||
{
|
||||
head.Split = new Header.Types.Split
|
||||
{
|
||||
Parent = split.Parent?.ToGrpcMessage(),
|
||||
ParentSignature = split.ParentSignature?.ToGrpcMessage(),
|
||||
ParentHeader = split.ParentHeader?.ToGrpcMessage(),
|
||||
Previous = split.Previous?.ToGrpcMessage(),
|
||||
SplitId = split.SplitId != null ? ByteString.CopyFrom(split.SplitId.ToBinary()) : null
|
||||
};
|
||||
|
||||
if (split.Children != null && split.Children.Any())
|
||||
head.Split.Children.AddRange(split.Children.Select(id => id.ToGrpcMessage()));
|
||||
}
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
public static ObjectHeader ToModel(this Header header)
|
||||
{
|
||||
var objTypeName = Enum.GetName(typeof(ModelsV2.Enums.ObjectType), header.ObjectType)
|
||||
?? throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.");
|
||||
var objTypeName = header.ObjectType switch
|
||||
{
|
||||
ObjectType.Regular => ModelsV2.Enums.ObjectType.Regular,
|
||||
ObjectType.Lock => ModelsV2.Enums.ObjectType.Lock,
|
||||
ObjectType.Tombstone => ModelsV2.Enums.ObjectType.Tombstone,
|
||||
_ => throw new ArgumentException($"Unknown ObjectType. Value: '{header.ObjectType}'.")
|
||||
};
|
||||
|
||||
return new ObjectHeader(
|
||||
ContainerId.FromHash(header.ContainerId.Value.ToByteArray()),
|
||||
(ModelsV2.Enums.ObjectType)Enum.Parse(typeof(ModelsV2.Enums.ObjectType), objTypeName),
|
||||
new ContainerId(Base58.Encode(header.ContainerId.Value.ToByteArray())),
|
||||
objTypeName,
|
||||
header.Attributes.Select(attribute => attribute.ToModel()).ToArray()
|
||||
)
|
||||
{
|
||||
Size = (long)header.PayloadLength,
|
||||
PayloadLength = header.PayloadLength,
|
||||
Version = header.Version.ToModel()
|
||||
};
|
||||
}
|
||||
|
@ -81,11 +119,33 @@ public static class ObjectMapper
|
|||
{
|
||||
public static ModelsV2.Object ToModel(this Object.Object obj)
|
||||
{
|
||||
return new ModelsV2.Object
|
||||
return new ModelsV2.Object()
|
||||
{
|
||||
Header = obj.Header.ToModel(),
|
||||
ObjectId = ObjectId.FromHash(obj.ObjectId.Value.ToByteArray()),
|
||||
Payload = obj.Payload.ToByteArray()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SignatureMapper
|
||||
{
|
||||
public static Refs.Signature ToGrpcMessage(this Signature signature)
|
||||
{
|
||||
var scheme = signature.Scheme switch
|
||||
{
|
||||
SignatureScheme.EcdsaRfc6979Sha256 => Refs.SignatureScheme.EcdsaRfc6979Sha256,
|
||||
SignatureScheme.EcdsaRfc6979Sha256WalletConnect => Refs.SignatureScheme.EcdsaRfc6979Sha256WalletConnect,
|
||||
SignatureScheme.EcdsaSha512 => Refs.SignatureScheme.EcdsaSha512,
|
||||
_ => throw new ArgumentException(message: $"Unexpected enum value: {signature.Scheme}", paramName: nameof(signature.Scheme))
|
||||
};
|
||||
|
||||
return new Refs.Signature
|
||||
{
|
||||
Key = ByteString.CopyFrom(signature.Key),
|
||||
Scheme = scheme,
|
||||
Sign = ByteString.CopyFrom(signature.Sign)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue