Switch to binary serialization; add IEntityComment interface
- Introduced IEntityComment interface for entity comments. - Changed SignalR client message serialization to binary. - Updated SignalResponseDataMessage docs for GZip (was Brotli). - Refactored GetResponseData<T> for GZip decompression and improved error handling. - Added necessary using statements for new interface and features.
This commit is contained in:
commit
d900442468
|
|
@ -0,0 +1,15 @@
|
|||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AyCode.Interfaces.EntityComment
|
||||
{
|
||||
public interface IEntityComment
|
||||
{
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using AyCode.Core.Extensions;
|
||||
using AyCode.Core.Helpers;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Core.Serializers.Binaries;
|
||||
using AyCode.Core.Serializers.Jsons;
|
||||
using AyCode.Services.SignalRs;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
|
@ -14,7 +15,7 @@ public abstract class AcSignalRSendToClientService<TSignalRHub, TSignalRTags, TL
|
|||
|
||||
protected virtual async Task SendMessageToClient(IAcSignalRHubItemServer sendTo, int messageTag, object? content)
|
||||
{
|
||||
var response = new SignalResponseDataMessage(messageTag, SignalResponseStatus.Success, content, AcJsonSerializerOptions.Default);
|
||||
var response = new SignalResponseDataMessage(messageTag, SignalResponseStatus.Success, content, AcBinarySerializerOptions.Default);
|
||||
var responseBytes = response.ToBinary();
|
||||
|
||||
Logger.Info($"[{responseBytes.Length / 1024}kb] Server sending to client; {ConstHelper.NameByValue<TSignalRTags>(messageTag)}");
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ public enum SignalResponseStatus : byte
|
|||
|
||||
/// <summary>
|
||||
/// Unified signal response message that supports both JSON and Binary serialization.
|
||||
/// JSON mode uses Brotli compression for reduced payload size.
|
||||
/// JSON mode uses GZip compression for reduced payload size.
|
||||
/// Optimized: uses pooled buffers for decompression, zero-copy deserialization path.
|
||||
/// </summary>
|
||||
public sealed class SignalResponseDataMessage : ISignalResponseMessage, IDisposable
|
||||
|
|
@ -183,28 +183,29 @@ public sealed class SignalResponseDataMessage : ISignalResponseMessage, IDisposa
|
|||
if (_cachedResponseData != null) return (T)_cachedResponseData;
|
||||
if (ResponseData == null) return default;
|
||||
|
||||
if (DataSerializerType == AcSerializerType.Binary)
|
||||
try
|
||||
{
|
||||
try
|
||||
if (DataSerializerType == AcSerializerType.Binary)
|
||||
{
|
||||
// Log diagnostics if enabled
|
||||
LogResponseDataDiagnostics<T>();
|
||||
|
||||
|
||||
return (T)(_cachedResponseData = ResponseData.BinaryTo<T>()!);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log detailed error diagnostics
|
||||
LogResponseDataError<T>(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Decompress Brotli to pooled buffer and deserialize directly
|
||||
EnsureDecompressed();
|
||||
var result = AcJsonDeserializer.Deserialize<T>(new ReadOnlySpan<byte>(_rentedDecompressedBuffer, 0, _decompressedLength));
|
||||
_cachedResponseData = result;
|
||||
return result;
|
||||
// Decompress GZip to pooled buffer and deserialize directly
|
||||
EnsureDecompressed();
|
||||
|
||||
var result = AcJsonDeserializer.Deserialize<T>(new ReadOnlySpan<byte>(_rentedDecompressedBuffer, 0, _decompressedLength));
|
||||
_cachedResponseData = result;
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log detailed error diagnostics
|
||||
LogResponseDataError<T>(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void LogResponseDataDiagnostics<T>()
|
||||
|
|
|
|||
Loading…
Reference in New Issue