@@ -78,7 +78,7 @@ private static T[] ReadBsonArray<T>(
78
78
var span = bytes . AsSpan ( ) ;
79
79
80
80
var result = new List < T > ( ) ;
81
-
81
+
82
82
var index = 4 ; // 4 first bytes are array object size in bytes
83
83
var maxIndex = array . Length - 1 ;
84
84
@@ -98,12 +98,14 @@ private static T[] ReadBsonArray<T>(
98
98
case ConversionType . DoubleToSingle :
99
99
{
100
100
var v = ( float ) BinaryPrimitivesCompat . ReadDoubleLittleEndian ( span . Slice ( index ) ) ;
101
+
101
102
value = Unsafe . As < float , T > ( ref v ) ;
102
103
break ;
103
104
}
104
105
case ConversionType . DoubleToDouble :
105
106
{
106
- var v = BitConverter . Int64BitsToDouble ( BinaryPrimitives . ReadInt64LittleEndian ( span . Slice ( index ) ) ) ;
107
+ var v = BinaryPrimitivesCompat . ReadDoubleLittleEndian ( span . Slice ( index ) ) ;
108
+
107
109
value = Unsafe . As < double , T > ( ref v ) ;
108
110
break ;
109
111
}
@@ -112,19 +114,22 @@ private static T[] ReadBsonArray<T>(
112
114
var lowBits = BinaryPrimitives . ReadUInt64LittleEndian ( span . Slice ( index ) ) ;
113
115
var highBits = BinaryPrimitives . ReadUInt64LittleEndian ( span . Slice ( index + 8 ) ) ;
114
116
var v = Decimal128 . ToDecimal ( Decimal128 . FromIEEEBits ( highBits , lowBits ) ) ;
117
+
115
118
value = Unsafe . As < decimal , T > ( ref v ) ;
116
119
break ;
117
120
}
118
121
case ConversionType . BoolToBool :
119
122
{
120
123
var v = span [ index ] != 0 ;
124
+
121
125
value = Unsafe . As < bool , T > ( ref v ) ;
122
126
break ;
123
127
}
124
128
case ConversionType . Int32ToInt8 :
125
129
{
126
130
var v = ( sbyte ) BinaryPrimitives . ReadInt32LittleEndian ( span . Slice ( index ) ) ;
127
131
value = Unsafe . As < sbyte , T > ( ref v ) ;
132
+
128
133
break ;
129
134
}
130
135
case ConversionType . Int32ToUInt8 :
@@ -180,10 +185,12 @@ private static T[] ReadBsonArray<T>(
180
185
}
181
186
182
187
result . Add ( value ) ;
188
+
183
189
index += bsonDataSize ;
184
190
}
185
191
186
192
ValidateBsonType ( BsonType . EndOfDocument , span ) ;
193
+
187
194
return result . ToArray ( ) ;
188
195
189
196
void ValidateBsonType ( BsonType bsonType , Span < byte > span )
0 commit comments