File tree Expand file tree Collapse file tree 3 files changed +17
-22
lines changed Expand file tree Collapse file tree 3 files changed +17
-22
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace MySql . Data
4
4
{
5
- internal sealed class ByteArrayReader
5
+ internal struct ByteArrayReader
6
6
{
7
7
public ByteArrayReader ( byte [ ] buffer , int offset , int length )
8
8
{
@@ -118,6 +118,8 @@ public ulong ReadLengthEncodedInteger()
118
118
byte encodedLength = m_buffer [ m_offset ++ ] ;
119
119
switch ( encodedLength )
120
120
{
121
+ case 0xFB :
122
+ throw new FormatException ( "Length-encoded integer cannot have 0xFB prefix byte." ) ;
121
123
case 0xFC :
122
124
return ReadFixedLengthUInt32 ( 2 ) ;
123
125
case 0xFD :
@@ -131,6 +133,17 @@ public ulong ReadLengthEncodedInteger()
131
133
}
132
134
}
133
135
136
+ public int ReadLengthEncodedIntegerOrNull ( )
137
+ {
138
+ if ( m_buffer [ m_offset ] == 0xFB )
139
+ {
140
+ // "NULL is sent as 0xfb" (https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-ProtocolText::ResultsetRow)
141
+ m_offset ++ ;
142
+ return - 1 ;
143
+ }
144
+ return checked ( ( int ) ReadLengthEncodedInteger ( ) ) ;
145
+ }
146
+
134
147
public ArraySegment < byte > ReadLengthEncodedByteString ( )
135
148
{
136
149
var length = checked ( ( int ) ReadLengthEncodedInteger ( ) ) ;
Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ Row ScanRowAsyncRemainder(PayloadData payload)
197
197
var reader = new ByteArrayReader ( payload . ArraySegment ) ;
198
198
for ( var column = 0 ; column < m_dataOffsets . Length ; column ++ )
199
199
{
200
- var length = checked ( ( int ) ReadFieldLength ( reader ) ) ;
200
+ var length = reader . ReadLengthEncodedIntegerOrNull ( ) ;
201
201
m_dataLengths [ column ] = length == - 1 ? 0 : length ;
202
202
m_dataOffsets [ column ] = length == - 1 ? - 1 : reader . Offset ;
203
203
reader . Offset += m_dataLengths [ column ] ;
@@ -211,24 +211,6 @@ Row ScanRowAsyncRemainder(PayloadData payload)
211
211
}
212
212
}
213
213
214
- private static long ReadFieldLength ( ByteArrayReader reader )
215
- {
216
- var leadByte = reader . ReadByte ( ) ;
217
- switch ( leadByte )
218
- {
219
- case 0xFB :
220
- return - 1 ;
221
- case 0xFC :
222
- return reader . ReadFixedLengthUInt32 ( 2 ) ;
223
- case 0xFD :
224
- return reader . ReadFixedLengthUInt32 ( 3 ) ;
225
- case 0xFE :
226
- return checked ( ( long ) reader . ReadFixedLengthUInt64 ( 8 ) ) ;
227
- default :
228
- return leadByte ;
229
- }
230
- }
231
-
232
214
public string GetName ( int ordinal )
233
215
{
234
216
if ( ColumnDefinitions == null )
Original file line number Diff line number Diff line change 1
- using System ;
1
+ using System ;
2
2
3
3
namespace MySql . Data . Serialization
4
4
{
5
- internal class PayloadData
5
+ internal struct PayloadData
6
6
{
7
7
public PayloadData ( ArraySegment < byte > data )
8
8
{
You can’t perform that action at this time.
0 commit comments