using System;
using System.Globalization;
namespace KcpSharp
{
///
/// The result of a receive or peek operation.
///
public readonly struct KcpConversationReceiveResult : IEquatable
{
private readonly int _bytesReceived;
private readonly bool _connectionAlive;
///
/// The number of bytes received.
///
public int BytesReceived => _bytesReceived;
///
/// Whether the underlying transport is marked as closed.
///
public bool TransportClosed => !_connectionAlive;
///
/// Construct a with the specified number of bytes received.
///
/// The number of bytes received.
public KcpConversationReceiveResult(int bytesReceived)
{
_bytesReceived = bytesReceived;
_connectionAlive = true;
}
///
/// Checks whether the two instance is equal.
///
/// The one instance.
/// The other instance.
/// Whether the two instance is equal
public static bool operator ==(KcpConversationReceiveResult left, KcpConversationReceiveResult right) => left.Equals(right);
///
/// Checks whether the two instance is not equal.
///
/// The one instance.
/// The other instance.
/// Whether the two instance is not equal
public static bool operator !=(KcpConversationReceiveResult left, KcpConversationReceiveResult right) => !left.Equals(right);
///
public bool Equals(KcpConversationReceiveResult other) => BytesReceived == other.BytesReceived && TransportClosed == other.TransportClosed;
///
public override bool Equals(object? obj) => obj is KcpConversationReceiveResult other && Equals(other);
///
public override int GetHashCode() => HashCode.Combine(BytesReceived, TransportClosed);
///
public override string ToString() => _connectionAlive ? _bytesReceived.ToString(CultureInfo.InvariantCulture) : "Transport is closed.";
}
}