@@ -95,8 +95,8 @@ public static void DecimalToAmqp(decimal value, out byte scale, out int mantissa
95
95
96
96
public static IList ReadArray ( ReadOnlyMemory < byte > memory , out int bytesRead )
97
97
{
98
- uint arrayLength = NetworkOrderDeserializer . ReadUInt32 ( memory ) ;
99
- List < object > array = new List < object > ( ( int ) arrayLength ) ;
98
+ List < object > array = new List < object > ( ) ;
99
+ long arrayLength = NetworkOrderDeserializer . ReadUInt32 ( memory . Span ) ;
100
100
bytesRead = 4 ;
101
101
while ( bytesRead - 4 < arrayLength )
102
102
{
@@ -111,7 +111,7 @@ public static IList ReadArray(ReadOnlyMemory<byte> memory, out int bytesRead)
111
111
public static decimal ReadDecimal ( ReadOnlyMemory < byte > memory )
112
112
{
113
113
byte scale = memory . Span [ 0 ] ;
114
- uint unsignedMantissa = NetworkOrderDeserializer . ReadUInt32 ( memory . Slice ( 1 ) ) ;
114
+ uint unsignedMantissa = NetworkOrderDeserializer . ReadUInt32 ( memory . Slice ( 1 ) . Span ) ;
115
115
return AmqpToDecimal ( scale , unsignedMantissa ) ;
116
116
}
117
117
@@ -127,10 +127,10 @@ public static object ReadFieldValue(ReadOnlyMemory<byte> memory, out int bytesRe
127
127
return result ;
128
128
case 'I' :
129
129
bytesRead += 4 ;
130
- return NetworkOrderDeserializer . ReadInt32 ( slice ) ;
130
+ return NetworkOrderDeserializer . ReadInt32 ( slice . Span ) ;
131
131
case 'i' :
132
132
bytesRead += 4 ;
133
- return NetworkOrderDeserializer . ReadUInt32 ( slice ) ;
133
+ return NetworkOrderDeserializer . ReadUInt32 ( slice . Span ) ;
134
134
case 'D' :
135
135
bytesRead += 5 ;
136
136
return ReadDecimal ( slice ) ;
@@ -153,16 +153,16 @@ public static object ReadFieldValue(ReadOnlyMemory<byte> memory, out int bytesRe
153
153
return ( sbyte ) slice . Span [ 0 ] ;
154
154
case 'd' :
155
155
bytesRead += 8 ;
156
- return NetworkOrderDeserializer . ReadDouble ( slice ) ;
156
+ return NetworkOrderDeserializer . ReadDouble ( slice . Span ) ;
157
157
case 'f' :
158
158
bytesRead += 4 ;
159
- return NetworkOrderDeserializer . ReadSingle ( slice ) ;
159
+ return NetworkOrderDeserializer . ReadSingle ( slice . Span ) ;
160
160
case 'l' :
161
161
bytesRead += 8 ;
162
- return NetworkOrderDeserializer . ReadInt64 ( slice ) ;
162
+ return NetworkOrderDeserializer . ReadInt64 ( slice . Span ) ;
163
163
case 's' :
164
164
bytesRead += 2 ;
165
- return NetworkOrderDeserializer . ReadInt16 ( slice ) ;
165
+ return NetworkOrderDeserializer . ReadInt16 ( slice . Span ) ;
166
166
case 't' :
167
167
bytesRead += 1 ;
168
168
return slice . Span [ 0 ] != 0 ;
@@ -179,7 +179,7 @@ public static object ReadFieldValue(ReadOnlyMemory<byte> memory, out int bytesRe
179
179
180
180
public static byte [ ] ReadLongstr ( ReadOnlyMemory < byte > memory )
181
181
{
182
- int byteCount = ( int ) NetworkOrderDeserializer . ReadUInt32 ( memory ) ;
182
+ int byteCount = ( int ) NetworkOrderDeserializer . ReadUInt32 ( memory . Span ) ;
183
183
if ( byteCount > int . MaxValue )
184
184
{
185
185
throw new SyntaxErrorException ( $ "Long string too long; byte length={ byteCount } , max={ int . MaxValue } ") ;
@@ -211,7 +211,7 @@ public static string ReadShortstr(ReadOnlyMemory<byte> memory, out int bytesRead
211
211
public static Dictionary < string , object > ReadTable ( ReadOnlyMemory < byte > memory , out int bytesRead )
212
212
{
213
213
Dictionary < string , object > table = new Dictionary < string , object > ( ) ;
214
- long tableLength = NetworkOrderDeserializer . ReadUInt32 ( memory ) ;
214
+ long tableLength = NetworkOrderDeserializer . ReadUInt32 ( memory . Span ) ;
215
215
bytesRead = 4 ;
216
216
while ( ( bytesRead - 4 ) < tableLength )
217
217
{
@@ -231,7 +231,7 @@ public static Dictionary<string, object> ReadTable(ReadOnlyMemory<byte> memory,
231
231
232
232
public static AmqpTimestamp ReadTimestamp ( ReadOnlyMemory < byte > memory )
233
233
{
234
- ulong stamp = NetworkOrderDeserializer . ReadUInt64 ( memory ) ;
234
+ ulong stamp = NetworkOrderDeserializer . ReadUInt64 ( memory . Span ) ;
235
235
// 0-9 is afaict silent on the signedness of the timestamp.
236
236
// See also MethodArgumentWriter.WriteTimestamp and AmqpTimestamp itself
237
237
return new AmqpTimestamp ( ( long ) stamp ) ;
@@ -241,7 +241,7 @@ public static int WriteArray(Memory<byte> memory, IList val)
241
241
{
242
242
if ( val == null )
243
243
{
244
- NetworkOrderSerializer . WriteUInt32 ( memory , 0 ) ;
244
+ NetworkOrderSerializer . WriteUInt32 ( memory . Span , 0 ) ;
245
245
return 4 ;
246
246
}
247
247
else
@@ -252,7 +252,7 @@ public static int WriteArray(Memory<byte> memory, IList val)
252
252
bytesWritten += WriteFieldValue ( memory . Slice ( 4 + bytesWritten ) , val [ index ] ) ;
253
253
}
254
254
255
- NetworkOrderSerializer . WriteUInt32 ( memory , ( uint ) bytesWritten ) ;
255
+ NetworkOrderSerializer . WriteUInt32 ( memory . Span , ( uint ) bytesWritten ) ;
256
256
return 4 + bytesWritten ;
257
257
}
258
258
}
@@ -296,7 +296,7 @@ public static int WriteFieldValue(Memory<byte> memory, object value)
296
296
if ( MemoryMarshal . TryGetArray ( memory , out ArraySegment < byte > segment ) )
297
297
{
298
298
int bytesWritten = Encoding . UTF8 . GetBytes ( val , 0 , val . Length , segment . Array , segment . Offset + 5 ) ;
299
- NetworkOrderSerializer . WriteUInt32 ( slice , ( uint ) bytesWritten ) ;
299
+ NetworkOrderSerializer . WriteUInt32 ( slice . Span , ( uint ) bytesWritten ) ;
300
300
return 5 + bytesWritten ;
301
301
}
302
302
@@ -306,11 +306,11 @@ public static int WriteFieldValue(Memory<byte> memory, object value)
306
306
return 1 + WriteLongstr ( slice , val ) ;
307
307
case int val :
308
308
memory . Span [ 0 ] = ( byte ) 'I' ;
309
- NetworkOrderSerializer . WriteInt32 ( slice , val ) ;
309
+ NetworkOrderSerializer . WriteInt32 ( slice . Span , val ) ;
310
310
return 5 ;
311
311
case uint val :
312
312
memory . Span [ 0 ] = ( byte ) 'i' ;
313
- NetworkOrderSerializer . WriteUInt32 ( slice , val ) ;
313
+ NetworkOrderSerializer . WriteUInt32 ( slice . Span , val ) ;
314
314
return 5 ;
315
315
case decimal val :
316
316
memory . Span [ 0 ] = ( byte ) 'D' ;
@@ -334,19 +334,19 @@ public static int WriteFieldValue(Memory<byte> memory, object value)
334
334
return 2 ;
335
335
case double val :
336
336
memory . Span [ 0 ] = ( byte ) 'd' ;
337
- NetworkOrderSerializer . WriteDouble ( slice , val ) ;
337
+ NetworkOrderSerializer . WriteDouble ( slice . Span , val ) ;
338
338
return 9 ;
339
339
case float val :
340
340
memory . Span [ 0 ] = ( byte ) 'f' ;
341
- NetworkOrderSerializer . WriteSingle ( slice , val ) ;
341
+ NetworkOrderSerializer . WriteSingle ( slice . Span , val ) ;
342
342
return 5 ;
343
343
case long val :
344
344
memory . Span [ 0 ] = ( byte ) 'l' ;
345
- NetworkOrderSerializer . WriteInt64 ( slice , val ) ;
345
+ NetworkOrderSerializer . WriteInt64 ( slice . Span , val ) ;
346
346
return 9 ;
347
347
case short val :
348
348
memory . Span [ 0 ] = ( byte ) 's' ;
349
- NetworkOrderSerializer . WriteInt16 ( slice , val ) ;
349
+ NetworkOrderSerializer . WriteInt16 ( slice . Span , val ) ;
350
350
return 3 ;
351
351
case bool val :
352
352
memory . Span [ 0 ] = ( byte ) 't' ;
@@ -399,13 +399,13 @@ public static int GetFieldValueByteCount(object value)
399
399
400
400
public static int WriteLong ( Memory < byte > memory , uint val )
401
401
{
402
- NetworkOrderSerializer . WriteUInt32 ( memory , val ) ;
402
+ NetworkOrderSerializer . WriteUInt32 ( memory . Span , val ) ;
403
403
return 4 ;
404
404
}
405
405
406
406
public static int WriteLonglong ( Memory < byte > memory , ulong val )
407
407
{
408
- NetworkOrderSerializer . WriteUInt64 ( memory , val ) ;
408
+ NetworkOrderSerializer . WriteUInt64 ( memory . Span , val ) ;
409
409
return 8 ;
410
410
}
411
411
@@ -423,7 +423,7 @@ public static int WriteLongstr(Memory<byte> memory, byte[] val, int index, int c
423
423
424
424
public static int WriteShort ( Memory < byte > memory , ushort val )
425
425
{
426
- NetworkOrderSerializer . WriteUInt16 ( memory , val ) ;
426
+ NetworkOrderSerializer . WriteUInt16 ( memory . Span , val ) ;
427
427
return 2 ;
428
428
}
429
429
@@ -448,7 +448,7 @@ public static int WriteTable(Memory<byte> memory, IDictionary val)
448
448
{
449
449
if ( val == null )
450
450
{
451
- NetworkOrderSerializer . WriteUInt32 ( memory , 0 ) ;
451
+ NetworkOrderSerializer . WriteUInt32 ( memory . Span , 0 ) ;
452
452
return 4 ;
453
453
}
454
454
else
@@ -462,7 +462,7 @@ public static int WriteTable(Memory<byte> memory, IDictionary val)
462
462
bytesWritten += WriteFieldValue ( slice . Slice ( bytesWritten ) , entry . Value ) ;
463
463
}
464
464
465
- NetworkOrderSerializer . WriteUInt32 ( memory , ( uint ) bytesWritten ) ;
465
+ NetworkOrderSerializer . WriteUInt32 ( memory . Span , ( uint ) bytesWritten ) ;
466
466
return 4 + bytesWritten ;
467
467
}
468
468
}
@@ -471,7 +471,7 @@ public static int WriteTable(Memory<byte> memory, IDictionary<string, object> va
471
471
{
472
472
if ( val == null )
473
473
{
474
- NetworkOrderSerializer . WriteUInt32 ( memory , 0 ) ;
474
+ NetworkOrderSerializer . WriteUInt32 ( memory . Span , 0 ) ;
475
475
return 4 ;
476
476
}
477
477
else
@@ -485,7 +485,7 @@ public static int WriteTable(Memory<byte> memory, IDictionary<string, object> va
485
485
bytesWritten += WriteFieldValue ( slice . Slice ( bytesWritten ) , entry . Value ) ;
486
486
}
487
487
488
- NetworkOrderSerializer . WriteUInt32 ( memory , ( uint ) bytesWritten ) ;
488
+ NetworkOrderSerializer . WriteUInt32 ( memory . Span , ( uint ) bytesWritten ) ;
489
489
return 4 + bytesWritten ;
490
490
}
491
491
}
0 commit comments