@@ -142,72 +142,6 @@ public bool TryDeserializeComponentDescriptorCollection(string serializedCompone
142
142
return true ;
143
143
}
144
144
145
- public bool TryDeserializeRootComponentOperations ( string serializedComponentOperations , [ NotNullWhen ( true ) ] out CircuitRootComponentOperation [ ] ? operations )
146
- {
147
- int [ ] ? seenComponentIdsStorage = null ;
148
- try
149
- {
150
- var result = JsonSerializer . Deserialize < RootComponentOperation [ ] > (
151
- serializedComponentOperations ,
152
- ServerComponentSerializationSettings . JsonSerializationOptions ) ;
153
-
154
- operations = new CircuitRootComponentOperation [ result . Length ] ;
155
-
156
- Span < int > seenSsrComponentIds = result . Length <= 128
157
- ? stackalloc int [ result . Length ]
158
- : ( seenComponentIdsStorage = ArrayPool < int > . Shared . Rent ( result . Length ) ) . AsSpan ( 0 , result . Length ) ;
159
- var currentSsrComponentIdIndex = 0 ;
160
- for ( var i = 0 ; i < result . Length ; i ++ )
161
- {
162
- var operation = result [ i ] ;
163
- if ( seenSsrComponentIds [ 0 ..currentSsrComponentIdIndex ] . Contains ( operation . SsrComponentId ) )
164
- {
165
- Log . InvalidRootComponentOperation ( _logger , operation . Type , message : "Duplicate component ID." ) ;
166
- operations = null ;
167
- return false ;
168
- }
169
-
170
- seenSsrComponentIds [ currentSsrComponentIdIndex ++ ] = operation . SsrComponentId ;
171
-
172
- if ( operation . Type == RootComponentOperationType . Remove )
173
- {
174
- operations [ i ] = new ( operation , null ) ;
175
- continue ;
176
- }
177
-
178
- if ( operation . Marker == null )
179
- {
180
- Log . InvalidRootComponentOperation ( _logger , operation . Type , message : "Missing marker." ) ;
181
- operations = null ;
182
- return false ;
183
- }
184
-
185
- if ( ! TryDeserializeWebRootComponentDescriptor ( operation . Marker . Value , out var descriptor ) )
186
- {
187
- operations = null ;
188
- return false ;
189
- }
190
-
191
- operations [ i ] = new ( operation , descriptor ) ;
192
- }
193
-
194
- return true ;
195
- }
196
- catch ( Exception ex )
197
- {
198
- Log . FailedToProcessRootComponentOperations ( _logger , ex ) ;
199
- operations = null ;
200
- return false ;
201
- }
202
- finally
203
- {
204
- if ( seenComponentIdsStorage != null )
205
- {
206
- ArrayPool < int > . Shared . Return ( seenComponentIdsStorage ) ;
207
- }
208
- }
209
- }
210
-
211
145
public bool TryDeserializeWebRootComponentDescriptor ( ComponentMarker record , [ NotNullWhen ( true ) ] out WebRootComponentDescriptor ? result )
212
146
{
213
147
result = default ;
@@ -263,26 +197,25 @@ public bool TryDeserializeWebRootComponentDescriptor(ComponentMarker record, [No
263
197
return true ;
264
198
}
265
199
266
- private ( ComponentDescriptor , ServerComponent ) DeserializeComponentDescriptor ( ComponentMarker record )
200
+ private bool TryDeserializeComponentTypeAndParameters ( ServerComponent serverComponent , [ NotNullWhen ( true ) ] out Type ? componentType , out ParameterView parameters )
267
201
{
268
- if ( ! TryDeserializeServerComponent ( record , out var serverComponent ) )
202
+ parameters = default ;
203
+ componentType = _rootComponentTypeCache
204
+ . GetRootComponent ( serverComponent . AssemblyName , serverComponent . TypeName ) ;
205
+
206
+ if ( componentType == null )
269
207
{
270
- return default ;
208
+ Log . FailedToFindComponent ( _logger , serverComponent . TypeName , serverComponent . AssemblyName ) ;
209
+ return false ;
271
210
}
272
211
273
- if ( ! TryDeserializeComponentTypeAndParameters ( serverComponent , out var componentType , out var parameters ) )
212
+ if ( ! _parametersDeserializer . TryDeserializeParameters ( serverComponent . ParameterDefinitions , serverComponent . ParameterValues , out parameters ) )
274
213
{
214
+ // TryDeserializeParameters does appropriate logging.
275
215
return default ;
276
216
}
277
217
278
- var componentDescriptor = new ComponentDescriptor
279
- {
280
- ComponentType = componentType ,
281
- Parameters = parameters ,
282
- Sequence = serverComponent . Sequence ,
283
- } ;
284
-
285
- return ( componentDescriptor , serverComponent ) ;
218
+ return true ;
286
219
}
287
220
288
221
private bool TryDeserializeServerComponent ( ComponentMarker record , out ServerComponent result )
@@ -330,25 +263,92 @@ private bool TryDeserializeServerComponent(ComponentMarker record, out ServerCom
330
263
}
331
264
}
332
265
333
- private bool TryDeserializeComponentTypeAndParameters ( ServerComponent serverComponent , [ NotNullWhen ( true ) ] out Type ? componentType , out ParameterView parameters )
266
+ private ( ComponentDescriptor , ServerComponent ) DeserializeComponentDescriptor ( ComponentMarker record )
334
267
{
335
- parameters = default ;
336
- componentType = _rootComponentTypeCache
337
- . GetRootComponent ( serverComponent . AssemblyName , serverComponent . TypeName ) ;
338
-
339
- if ( componentType == null )
268
+ if ( ! TryDeserializeServerComponent ( record , out var serverComponent ) )
340
269
{
341
- Log . FailedToFindComponent ( _logger , serverComponent . TypeName , serverComponent . AssemblyName ) ;
342
- return false ;
270
+ return default ;
343
271
}
344
272
345
- if ( ! _parametersDeserializer . TryDeserializeParameters ( serverComponent . ParameterDefinitions , serverComponent . ParameterValues , out parameters ) )
273
+ if ( ! TryDeserializeComponentTypeAndParameters ( serverComponent , out var componentType , out var parameters ) )
346
274
{
347
- // TryDeserializeParameters does appropriate logging.
348
275
return default ;
349
276
}
350
277
351
- return true ;
278
+ var componentDescriptor = new ComponentDescriptor
279
+ {
280
+ ComponentType = componentType ,
281
+ Parameters = parameters ,
282
+ Sequence = serverComponent . Sequence ,
283
+ } ;
284
+
285
+ return ( componentDescriptor , serverComponent ) ;
286
+ }
287
+
288
+ public bool TryDeserializeRootComponentOperations ( string serializedComponentOperations , [ NotNullWhen ( true ) ] out CircuitRootComponentOperation [ ] ? operations )
289
+ {
290
+ int [ ] ? seenComponentIdsStorage = null ;
291
+ try
292
+ {
293
+ var result = JsonSerializer . Deserialize < RootComponentOperation [ ] > (
294
+ serializedComponentOperations ,
295
+ ServerComponentSerializationSettings . JsonSerializationOptions ) ;
296
+
297
+ operations = new CircuitRootComponentOperation [ result . Length ] ;
298
+
299
+ Span < int > seenSsrComponentIds = result . Length <= 128
300
+ ? stackalloc int [ result . Length ]
301
+ : ( seenComponentIdsStorage = ArrayPool < int > . Shared . Rent ( result . Length ) ) . AsSpan ( 0 , result . Length ) ;
302
+ var currentSsrComponentIdIndex = 0 ;
303
+ for ( var i = 0 ; i < result . Length ; i ++ )
304
+ {
305
+ var operation = result [ i ] ;
306
+ if ( seenSsrComponentIds [ 0 ..currentSsrComponentIdIndex ] . Contains ( operation . SsrComponentId ) )
307
+ {
308
+ Log . InvalidRootComponentOperation ( _logger , operation . Type , message : "Duplicate component ID." ) ;
309
+ operations = null ;
310
+ return false ;
311
+ }
312
+
313
+ seenSsrComponentIds [ currentSsrComponentIdIndex ++ ] = operation . SsrComponentId ;
314
+
315
+ if ( operation . Type == RootComponentOperationType . Remove )
316
+ {
317
+ operations [ i ] = new ( operation , null ) ;
318
+ continue ;
319
+ }
320
+
321
+ if ( operation . Marker == null )
322
+ {
323
+ Log . InvalidRootComponentOperation ( _logger , operation . Type , message : "Missing marker." ) ;
324
+ operations = null ;
325
+ return false ;
326
+ }
327
+
328
+ if ( ! TryDeserializeWebRootComponentDescriptor ( operation . Marker . Value , out var descriptor ) )
329
+ {
330
+ operations = null ;
331
+ return false ;
332
+ }
333
+
334
+ operations [ i ] = new ( operation , descriptor ) ;
335
+ }
336
+
337
+ return true ;
338
+ }
339
+ catch ( Exception ex )
340
+ {
341
+ Log . FailedToProcessRootComponentOperations ( _logger , ex ) ;
342
+ operations = null ;
343
+ return false ;
344
+ }
345
+ finally
346
+ {
347
+ if ( seenComponentIdsStorage != null )
348
+ {
349
+ ArrayPool < int > . Shared . Return ( seenComponentIdsStorage ) ;
350
+ }
351
+ }
352
352
}
353
353
354
354
private static partial class Log
0 commit comments