@@ -76,20 +76,18 @@ public static void SetDataPackageAdapter(this ITcpSocketClient client, IDataPack
7676 }
7777
7878 /// <summary>
79- /// Configures the specified <see cref="ITcpSocketClient"/> to use a custom data package adapter and a callback
80- /// function for processing received data.
79+ /// Configures the specified <see cref="ITcpSocketClient"/> to use a data package adapter and a callback function
80+ /// for processing received data.
8181 /// </summary>
82- /// <remarks>This method sets up the <paramref name="client"/> to use the provided <paramref
83- /// name="adapter"/> for handling incoming data. The adapter processes the raw data received by the client and
84- /// attempts to convert it into an instance of <typeparamref name="TEntity"/>. If the conversion is successful, the
85- /// <paramref name="callback"/> is invoked with the converted entity; otherwise, it is invoked with <see
86- /// langword="null"/>.</remarks>
87- /// <typeparam name="TEntity">The type of the entity that the data package adapter will attempt to convert the received data into.</typeparam>
88- /// <param name="client">The <see cref="ITcpSocketClient"/> instance to configure.</param>
89- /// <param name="adapter">The <see cref="IDataPackageAdapter"/> instance responsible for handling and processing incoming data.</param>
90- /// <param name="callback">A callback function to be invoked with the processed data of type <typeparamref name="TEntity"/>. The callback
91- /// receives <see langword="null"/> if the data cannot be converted to <typeparamref name="TEntity"/>.</param>
92- public static void SetDataPackageAdapter < TEntity > ( this ITcpSocketClient client , IDataPackageAdapter adapter , Func < TEntity ? , Task > callback )
82+ /// <remarks>This method sets up the <paramref name="client"/> to process incoming data using the
83+ /// specified <paramref name="adapter"/> and <paramref name="socketDataConverter"/>. The <paramref
84+ /// name="callback"/> is called with the converted entity whenever data is received.</remarks>
85+ /// <typeparam name="TEntity">The type of the entity that the data will be converted to.</typeparam>
86+ /// <param name="client">The TCP socket client to configure.</param>
87+ /// <param name="adapter">The data package adapter responsible for handling incoming data.</param>
88+ /// <param name="socketDataConverter">The converter used to transform the received data into the specified entity type.</param>
89+ /// <param name="callback">The callback function to be invoked with the converted entity.</param>
90+ public static void SetDataPackageAdapter < TEntity > ( this ITcpSocketClient client , IDataPackageAdapter adapter , ISocketDataConverter < TEntity > socketDataConverter , Func < TEntity ? , Task > callback )
9391 {
9492 // 设置 ITcpSocketClient 的回调函数
9593 client . ReceivedCallBack = async buffer =>
@@ -102,12 +100,9 @@ public static void SetDataPackageAdapter<TEntity>(this ITcpSocketClient client,
102100 adapter . ReceivedCallBack = async buffer =>
103101 {
104102 TEntity ? ret = default ;
105- if ( adapter . TryConvertTo ( buffer , out var t ) )
103+ if ( socketDataConverter . TryConvertTo ( buffer , out var t ) )
106104 {
107- if ( t is TEntity entity )
108- {
109- ret = entity ;
110- }
105+ ret = t ;
111106 }
112107 await callback ( ret ) ;
113108 } ;
0 commit comments