[#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
65
src/FrostFS.SDK.ModelsV2/Object/Object.cs
Normal file
65
src/FrostFS.SDK.ModelsV2/Object/Object.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System.Security.Cryptography;
|
||||
using FrostFS.SDK.ModelsV2.Enums;
|
||||
|
||||
namespace FrostFS.SDK.ModelsV2;
|
||||
|
||||
public class Object
|
||||
{
|
||||
public Object()
|
||||
{
|
||||
}
|
||||
|
||||
public Object(ContainerId container, byte[] payload, ObjectType objectType = ObjectType.Regular)
|
||||
{
|
||||
Payload = payload;
|
||||
Header = new ObjectHeader(containerId: container, type: objectType, attributes: []);
|
||||
}
|
||||
|
||||
public ObjectHeader Header { get; set; }
|
||||
public ObjectId ObjectId { get; set; }
|
||||
public byte[] Payload { get; set; }
|
||||
public Signature Signature { get; set; }
|
||||
|
||||
public void SetParent(LargeObject largeObject)
|
||||
{
|
||||
Header.Split!.ParentHeader = largeObject.Header;
|
||||
}
|
||||
|
||||
public ObjectId? GetParentId()
|
||||
{
|
||||
return Header.Split?.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
public class LargeObject(ContainerId container) : Object(container, [])
|
||||
{
|
||||
private SHA256 payloadHash = SHA256.Create();
|
||||
|
||||
public void AppendBlock(byte[] bytes, int count)
|
||||
{
|
||||
Header.PayloadLength += (ulong)count;
|
||||
this.payloadHash.TransformBlock(bytes, 0, count, bytes, 0);
|
||||
}
|
||||
|
||||
public void CalculateHash()
|
||||
{
|
||||
this.payloadHash.TransformFinalBlock([], 0, 0);
|
||||
Header.PayloadCheckSum = this.payloadHash.Hash;
|
||||
}
|
||||
|
||||
public ulong PayloadLength
|
||||
{
|
||||
get { return Header.PayloadLength; }
|
||||
}
|
||||
}
|
||||
|
||||
public class LinkObject : Object
|
||||
{
|
||||
public LinkObject(ContainerId containerId, SplitId splitId, LargeObject largeObject) : base (containerId, [])
|
||||
{
|
||||
Header.Split = new Split(splitId)
|
||||
{
|
||||
ParentHeader = largeObject.Header
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue