41
41
namespace RabbitMQ . Client . Unit
42
42
{
43
43
[ TestFixture ]
44
- class TestMethodArgumentCodec
44
+ public class TestMethodArgumentCodec
45
45
{
46
- public static MethodArgumentWriter Writer ( )
47
- {
48
- return new MethodArgumentWriter ( new byte [ 1024 ] ) ;
49
- }
50
-
51
- public static MethodArgumentReader Reader ( byte [ ] bytes )
52
- {
53
- return new MethodArgumentReader ( bytes ) ;
54
- }
55
-
56
46
public void Check ( byte [ ] actual , byte [ ] expected )
57
47
{
58
48
try
@@ -81,22 +71,22 @@ public void TestTableLengthWrite()
81
71
82
72
int bytesNeeded = WireFormatting . GetTableByteCount ( t ) ;
83
73
byte [ ] memory = new byte [ bytesNeeded ] ;
84
- var writer = new MethodArgumentWriter ( memory ) ;
85
- writer . WriteTable ( t ) ;
86
- Assert . AreEqual ( bytesNeeded , writer . Offset ) ;
74
+ int offset = WireFormatting . WriteTable ( memory . AsSpan ( ) , t ) ;
75
+ Assert . AreEqual ( bytesNeeded , offset ) ;
87
76
Check ( memory , new byte [ ] { 0x00 , 0x00 , 0x00 , 0x0C ,
88
77
0x03 , 0x61 , 0x62 , 0x63 ,
89
78
0x53 , 0x00 , 0x00 , 0x00 ,
90
79
0x03 , 0x64 , 0x65 , 0x66 } ) ;
91
80
}
92
81
93
82
[ Test ]
94
- public void TestTableLengthRead ( )
83
+ public void TestDictionaryLengthRead ( )
95
84
{
96
- IDictionary t = ( IDictionary ) Reader ( new byte [ ] { 0x00 , 0x00 , 0x00 , 0x0C ,
97
- 0x03 , 0x61 , 0x62 , 0x63 ,
98
- 0x53 , 0x00 , 0x00 , 0x00 ,
99
- 0x03 , 0x64 , 0x65 , 0x66 } ) . ReadTable ( ) ;
85
+ WireFormatting . ReadDictionary ( new byte [ ] {
86
+ 0x00 , 0x00 , 0x00 , 0x0C ,
87
+ 0x03 , 0x61 , 0x62 , 0x63 ,
88
+ 0x53 , 0x00 , 0x00 , 0x00 ,
89
+ 0x03 , 0x64 , 0x65 , 0x66 } , out var t ) ;
100
90
Assert . AreEqual ( Encoding . UTF8 . GetBytes ( "def" ) , t [ "abc" ] ) ;
101
91
Assert . AreEqual ( 1 , t . Count ) ;
102
92
}
@@ -112,9 +102,8 @@ public void TestNestedTableWrite()
112
102
t [ "x" ] = x ;
113
103
int bytesNeeded = WireFormatting . GetTableByteCount ( t ) ;
114
104
byte [ ] memory = new byte [ bytesNeeded ] ;
115
- var writer = new MethodArgumentWriter ( memory ) ;
116
- writer . WriteTable ( t ) ;
117
- Assert . AreEqual ( bytesNeeded , writer . Offset ) ;
105
+ int offset = WireFormatting . WriteTable ( memory . AsSpan ( ) , t ) ;
106
+ Assert . AreEqual ( bytesNeeded , offset ) ;
118
107
Check ( memory , new byte [ ] { 0x00 , 0x00 , 0x00 , 0x0E ,
119
108
0x01 , 0x78 , 0x46 , 0x00 ,
120
109
0x00 , 0x00 , 0x07 , 0x01 ,
0 commit comments