frostfs-sdk-csharp/src/FrostFS.SDK.Client/Parameters/PrmObjectPatch.cs
Pavel Gross 9bb7b5eff8 [#28] Clients: Make immutable parameters
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-12-02 19:33:45 +03:00

71 lines
2 KiB
C#

using System.IO;
namespace FrostFS.SDK.Client;
public readonly struct PrmObjectPatch(
FrostFsAddress address,
FrostFsRange range,
Stream? payload,
int maxChunkLength,
FrostFsSessionToken? sessionToken = null,
bool replaceAttributes = false,
FrostFsAttributePair[]? newAttributes = null,
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmObjectPatch>
{
public FrostFsAddress Address { get; } = address;
public FrostFsRange Range { get; } = range;
/// <summary>
/// A stream with source data
/// </summary>
public Stream? Payload { get; } = payload;
public FrostFsAttributePair[]? NewAttributes { get; } = newAttributes;
public bool ReplaceAttributes { get; } = replaceAttributes;
public int MaxChunkLength { get; } = maxChunkLength;
/// <inheritdoc />
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
/// <summary>
/// FrostFS request X-Headers
/// </summary>
public string[] XHeaders { get; } = xheaders ?? [];
public override readonly bool Equals(object obj)
{
if (obj == null || obj is not PrmObjectPatch)
return false;
return Equals((PrmObjectPatch)obj);
}
public readonly bool Equals(PrmObjectPatch other)
{
return GetHashCode() == other.GetHashCode();
}
public override readonly int GetHashCode()
{
return Address.GetHashCode()
^ Range.GetHashCode()
^ (Payload == null ? 0 : Payload.GetHashCode())
^ (NewAttributes == null ? 0 : NewAttributes.GetHashCode())
^ (SessionToken == null ? 0 : SessionToken.GetHashCode())
^ (ReplaceAttributes ? 1 : 0)
^ MaxChunkLength;
}
public static bool operator ==(PrmObjectPatch left, PrmObjectPatch right)
{
return left.Equals(right);
}
public static bool operator !=(PrmObjectPatch left, PrmObjectPatch right)
{
return !(left == right);
}
}