frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Tools/Object.cs
Pavel Gross 6562aa27a5 [#23] Client: Refactoring to optimize memory usage
Signed-off-by: Pavel Gross <p.gross@yando.com>
2024-09-11 10:58:00 +03:00

57 lines
No EOL
1.6 KiB
C#

using System;
using System.Collections.Generic;
namespace FrostFS.SDK.ClientV2.Extensions;
public static class ObjectExtensions
{
public static FrostFsObject SetPayloadLength(this FrostFsObject obj, ulong length)
{
obj.Header.PayloadLength = length;
return obj;
}
public static FrostFsObject SetPayload(this FrostFsObject obj, byte[] bytes)
{
obj.Payload = bytes;
return obj;
}
public static FrostFsObject AddAttribute(this FrostFsObject obj, string key, string value)
{
obj.AddAttribute(new FrostFsAttribute(key, value));
return obj;
}
public static FrostFsObject AddAttribute(this FrostFsObject obj, FrostFsAttribute attribute)
{
obj.Header.Attributes.Add(attribute);
return obj;
}
public static FrostFsObject AddAttributes(this FrostFsObject obj, IEnumerable<FrostFsAttribute> attributes)
{
obj.Header.Attributes.AddRange(attributes);
return obj;
}
public static FrostFsObject SetSplit(this FrostFsObject obj, FrostFsSplit? split)
{
obj.Header.Split = split;
return obj;
}
public static FrostFsLinkObject AddChildren(this FrostFsLinkObject linkObject, IEnumerable<FrostFsObjectId> objectIds)
{
linkObject.Header.Split!.Children.AddRange(objectIds);
return linkObject;
}
public static FrostFsObject CalculateObjectId(this FrostFsObject obj)
{
if (obj.Header == null)
throw new MissingFieldException("Header cannot be null");
return obj;
}
}