@@ -78,7 +78,7 @@ private static T[] ReadBsonArray<T>(
7878 var span = bytes . AsSpan ( ) ;
7979
8080 var result = new List < T > ( ) ;
81-
81+
8282 var index = 4 ; // 4 first bytes are array object size in bytes
8383 var maxIndex = array . Length - 1 ;
8484
@@ -98,12 +98,14 @@ private static T[] ReadBsonArray<T>(
9898 case ConversionType . DoubleToSingle :
9999 {
100100 var v = ( float ) BinaryPrimitivesCompat . ReadDoubleLittleEndian ( span . Slice ( index ) ) ;
101+
101102 value = Unsafe . As < float , T > ( ref v ) ;
102103 break ;
103104 }
104105 case ConversionType . DoubleToDouble :
105106 {
106- var v = BitConverter . Int64BitsToDouble ( BinaryPrimitives . ReadInt64LittleEndian ( span . Slice ( index ) ) ) ;
107+ var v = BinaryPrimitivesCompat . ReadDoubleLittleEndian ( span . Slice ( index ) ) ;
108+
107109 value = Unsafe . As < double , T > ( ref v ) ;
108110 break ;
109111 }
@@ -112,19 +114,22 @@ private static T[] ReadBsonArray<T>(
112114 var lowBits = BinaryPrimitives . ReadUInt64LittleEndian ( span . Slice ( index ) ) ;
113115 var highBits = BinaryPrimitives . ReadUInt64LittleEndian ( span . Slice ( index + 8 ) ) ;
114116 var v = Decimal128 . ToDecimal ( Decimal128 . FromIEEEBits ( highBits , lowBits ) ) ;
117+
115118 value = Unsafe . As < decimal , T > ( ref v ) ;
116119 break ;
117120 }
118121 case ConversionType . BoolToBool :
119122 {
120123 var v = span [ index ] != 0 ;
124+
121125 value = Unsafe . As < bool , T > ( ref v ) ;
122126 break ;
123127 }
124128 case ConversionType . Int32ToInt8 :
125129 {
126130 var v = ( sbyte ) BinaryPrimitives . ReadInt32LittleEndian ( span . Slice ( index ) ) ;
127131 value = Unsafe . As < sbyte , T > ( ref v ) ;
132+
128133 break ;
129134 }
130135 case ConversionType . Int32ToUInt8 :
@@ -180,10 +185,12 @@ private static T[] ReadBsonArray<T>(
180185 }
181186
182187 result . Add ( value ) ;
188+
183189 index += bsonDataSize ;
184190 }
185191
186192 ValidateBsonType ( BsonType . EndOfDocument , span ) ;
193+
187194 return result . ToArray ( ) ;
188195
189196 void ValidateBsonType ( BsonType bsonType , Span < byte > span )
0 commit comments