Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lagrange.Core/Internal/Context/SocketContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void OnDisconnect()

public void OnSocketError(Exception e, ReadOnlyMemory<byte> data)
{

_context.LogError(Tag, "Socket error occurred during packet processing: {0}", e, e.Message);
}

public async Task<bool> Connect()
Expand Down
15 changes: 14 additions & 1 deletion Lagrange.Core/Internal/Services/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ namespace Lagrange.Core.Internal.Services;

internal abstract class BaseService<TReq, TResp> : IService where TReq : ProtocolEvent where TResp : ProtocolEvent
{
private const string Tag = nameof(BaseService);

protected virtual ValueTask<TResp> Parse(ReadOnlyMemory<byte> input, BotContext context) => ValueTask.FromResult<TResp>(null!);

protected virtual ValueTask<ReadOnlyMemory<byte>> Build(TReq input, BotContext context) => ValueTask.FromResult(ReadOnlyMemory<byte>.Empty);

async ValueTask<ProtocolEvent> IService.Parse(ReadOnlyMemory<byte> input, BotContext context) => await Parse(input, context);
async ValueTask<ProtocolEvent> IService.Parse(ReadOnlyMemory<byte> input, BotContext context)
{
try
{
return await Parse(input, context);
}
catch (Exception e)
{
context.LogError(Tag, "Parse method failed for service {0}", e, GetType().Name);
throw;
}
}

ValueTask<ReadOnlyMemory<byte>> IService.Build(ProtocolEvent input, BotContext context) => Build((TReq)input, context);
}