Files
cneicy 8eaaa3040a
Publish UPM package / publish (push) Failing after 1s
chore: initialize standalone UPM package
2026-08-26 02:50:34 +08:00

72 lines
2.4 KiB
C#

#nullable enable
using System;
using System.Threading;
namespace ShrinkNetwork
{
public readonly struct ShrinkRequestToken : IEquatable<ShrinkRequestToken>
{
public static readonly ShrinkRequestToken Default = new(0);
public ShrinkRequestToken(int value)
{
Value = value;
}
public int Value { get; }
public bool IsDefault => Value == 0;
public bool Equals(ShrinkRequestToken other) => Value == other.Value;
public override bool Equals(object? obj) => obj is ShrinkRequestToken other && Equals(other);
public override int GetHashCode() => Value;
public override string ToString() => Value.ToString();
public static bool operator ==(ShrinkRequestToken left, ShrinkRequestToken right) => left.Equals(right);
public static bool operator !=(ShrinkRequestToken left, ShrinkRequestToken right) => !left.Equals(right);
public static explicit operator int(ShrinkRequestToken token) => token.Value;
public static explicit operator ShrinkRequestToken(int value) => new(value);
}
public sealed class ShrinkRpcCallOptions
{
public int TimeoutMs { get; set; } = 10000;
public string? RouteOverride { get; set; }
public ShrinkRequestToken? RequestTokenOverride { get; set; }
public string? DebugLabel { get; set; }
public CancellationToken CancellationToken { get; set; } = default;
}
public sealed class ShrinkRpcException : Exception
{
public int ErrorCode { get; }
public ShrinkRpcException(int errorCode, string message)
: base(message)
{
ErrorCode = errorCode;
}
}
public static class ShrinkRpcErrorCode
{
public const int Unknown = 1;
public const int Timeout = 2;
public const int Canceled = 3;
public const int HandlerException = 4;
public const int InvalidResponse = 5;
public const int PermissionDenied = 6;
public const int ConnectionClosed = 7;
public const int ProtocolMismatch = 8;
public const int AuthenticationFailed = 9;
public const int SessionTokenExpired = 10;
}
public abstract class ShrinkRpcResponseBase : IShrinkNetworkResponse
{
public int ErrorCode { get; set; }
public string ErrorMessage { get; set; } = string.Empty;
public bool IsSuccess => ErrorCode == 0;
}
}