using Ananta.SDK.Serialization;
using Ananta.SDK.Logging;
namespace Ananta.SDK.Rpc;
/// A parsed UX RPC message exposed to attribute handlers.
public sealed class UxRpcMessage
{
public RpcContext Context { get; }
public RpcPacketKind Kind => Context.Packet.Kind;
public uint MethodId => Context.MethodId;
public int InvokeId => Context.InvokeId;
public byte[] Body => Context.Body;
public bool IsInvoke => Kind == RpcPacketKind.Invoke;
public bool IsNotify => Kind == RpcPacketKind.Notify;
internal UxRpcMessage(RpcContext context) => Context = context;
public T GetArgs()
{
var value = UxSerializer.Deserialize(Body);
RuntimeLogs.Decoded(Context.Session.Log.Scope, "C2S", MethodId, typeof(T), value);
return value;
}
public bool TryGetArgs(out T value)
{
try
{
value = GetArgs();
return true;
}
catch
{
value = default!;
return false;
}
}
}