@@ -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
@@ -103,7 +103,7 @@ private static T[] ReadBsonArray<T>(
103103 }
104104 case ConversionType . DoubleToDouble :
105105 {
106- var v = BitConverter . Int64BitsToDouble ( BinaryPrimitives . ReadInt64LittleEndian ( span . Slice ( index ) ) ) ;
106+ var v = BinaryPrimitivesCompat . ReadDoubleLittleEndian ( span . Slice ( index ) ) ;
107107 value = Unsafe . As < double , T > ( ref v ) ;
108108 break ;
109109 }
@@ -112,19 +112,22 @@ private static T[] ReadBsonArray<T>(
112112 var lowBits = BinaryPrimitives . ReadUInt64LittleEndian ( span . Slice ( index ) ) ;
113113 var highBits = BinaryPrimitives . ReadUInt64LittleEndian ( span . Slice ( index + 8 ) ) ;
114114 var v = Decimal128 . ToDecimal ( Decimal128 . FromIEEEBits ( highBits , lowBits ) ) ;
115+
115116 value = Unsafe . As < decimal , T > ( ref v ) ;
116117 break ;
117118 }
118119 case ConversionType . BoolToBool :
119120 {
120121 var v = span [ index ] != 0 ;
122+
121123 value = Unsafe . As < bool , T > ( ref v ) ;
122124 break ;
123125 }
124126 case ConversionType . Int32ToInt8 :
125127 {
126128 var v = ( sbyte ) BinaryPrimitives . ReadInt32LittleEndian ( span . Slice ( index ) ) ;
127129 value = Unsafe . As < sbyte , T > ( ref v ) ;
130+
128131 break ;
129132 }
130133 case ConversionType . Int32ToUInt8 :
@@ -180,10 +183,12 @@ private static T[] ReadBsonArray<T>(
180183 }
181184
182185 result . Add ( value ) ;
186+
183187 index += bsonDataSize ;
184188 }
185189
186190 ValidateBsonType ( BsonType . EndOfDocument , span ) ;
191+
187192 return result . ToArray ( ) ;
188193
189194 void ValidateBsonType ( BsonType bsonType , Span < byte > span )
0 commit comments