Skip to content

Commit

Permalink
chore: minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyakunin committed Aug 24, 2023
1 parent 4c4c005 commit 37b2e56
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/Stl.Rpc/Infrastructure/RpcClientInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Stl.Rpc.Infrastructure;

public class RpcClientInterceptor(
RpcClientInterceptor.Options settings,
IServiceProvider services
) : RpcInterceptorBase(settings, services)
RpcClientInterceptor.Options settings,
IServiceProvider services
) : RpcInterceptorBase(settings, services)
{
public new record Options : RpcInterceptorBase.Options
{
Expand Down
6 changes: 3 additions & 3 deletions src/Stl.Rpc/Infrastructure/RpcInterceptorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Stl.Rpc.Infrastructure;

public abstract class RpcInterceptorBase(
RpcInterceptorBase.Options settings,
IServiceProvider services
) : InterceptorBase(settings, services)
RpcInterceptorBase.Options settings,
IServiceProvider services
) : InterceptorBase(settings, services)
{
public new record Options : InterceptorBase.Options;

Expand Down
36 changes: 14 additions & 22 deletions src/Stl.Rpc/Infrastructure/RpcMessage.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
namespace Stl.Rpc.Infrastructure;

[DataContract, MemoryPackable(GenerateType.VersionTolerant)]
public partial class RpcMessage
[method: JsonConstructor, Newtonsoft.Json.JsonConstructor, MemoryPackConstructor]
public partial class RpcMessage(
byte callTypeId,
long callId,
string service,
string method,
TextOrBytes argumentData,
List<RpcHeader>? headers)
{
[JsonInclude, DataMember(Order = 0), MemoryPackOrder(0)] public byte CallTypeId;
[JsonInclude, DataMember(Order = 1), MemoryPackOrder(1)] public long CallId;
[JsonInclude, DataMember(Order = 2), MemoryPackOrder(2)] public string Service;
[JsonInclude, DataMember(Order = 3), MemoryPackOrder(3)] public string Method;
[JsonInclude, DataMember(Order = 4), MemoryPackOrder(4)] public TextOrBytes ArgumentData;
[JsonInclude, DataMember(Order = 5), MemoryPackOrder(5)] public List<RpcHeader>? Headers;

[JsonConstructor, Newtonsoft.Json.JsonConstructor, MemoryPackConstructor]
public RpcMessage(
byte callTypeId, long callId,
string service, string method,
TextOrBytes argumentData,
List<RpcHeader>? headers)
{
CallTypeId = callTypeId;
CallId = callId;
Service = service;
Method = method;
ArgumentData = argumentData;
Headers = headers;
}
[JsonInclude, DataMember(Order = 0), MemoryPackOrder(0)] public byte CallTypeId = callTypeId;
[JsonInclude, DataMember(Order = 1), MemoryPackOrder(1)] public long CallId = callId;
[JsonInclude, DataMember(Order = 2), MemoryPackOrder(2)] public string Service = service;
[JsonInclude, DataMember(Order = 3), MemoryPackOrder(3)] public string Method = method;
[JsonInclude, DataMember(Order = 4), MemoryPackOrder(4)] public TextOrBytes ArgumentData = argumentData;
[JsonInclude, DataMember(Order = 5), MemoryPackOrder(5)] public List<RpcHeader>? Headers = headers;

public override string ToString()
{
Expand Down
14 changes: 4 additions & 10 deletions src/Stl.Rpc/Infrastructure/RpcOutboundCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Stl.Rpc.Infrastructure;

public abstract class RpcOutboundCall : RpcCall
public abstract class RpcOutboundCall(RpcOutboundContext context)
: RpcCall(context.MethodDef!)
{
private static readonly ConcurrentDictionary<(byte, Type), Func<RpcOutboundContext, RpcOutboundCall>> FactoryCache = new();

public readonly RpcOutboundContext Context;
public readonly RpcPeer Peer;
public readonly RpcOutboundContext Context = context;
public readonly RpcPeer Peer = context.Peer!; // Calls
public RpcMessage? Message;
public Task ResultTask { get; protected init; } = null!;
public TimeSpan ConnectTimeout;
Expand All @@ -24,13 +25,6 @@ public static RpcOutboundCall New(RpcOutboundContext context)
return (Func<RpcOutboundContext, RpcOutboundCall>)type.GetConstructorDelegate(typeof(RpcOutboundContext))!;
}).Invoke(context);

protected RpcOutboundCall(RpcOutboundContext context)
: base(context.MethodDef!)
{
Context = context;
Peer = context.Peer!; // Calls
}

public override string ToString()
{
var context = Context;
Expand Down

0 comments on commit 37b2e56

Please sign in to comment.