6262 } )
6363}
6464
65- fn decode_tinyint < T > ( bytes : & [ u8 ] , type_info : & MssqlTypeInfo ) -> Result < T , BoxDynError >
66- where
67- T : TryFrom < u8 > ,
68- T :: Error : std:: error:: Error + Send + Sync + ' static ,
69- {
70- if bytes. len ( ) != 1 {
71- return Err ( err_protocol ! (
72- "{} should have exactly 1 byte, got {}" ,
73- type_info,
74- bytes. len( )
75- )
76- . into ( ) ) ;
77- }
78-
79- let val = u8:: from_le_bytes ( [ bytes[ 0 ] ] ) ;
80- T :: try_from ( val) . map_err ( |err| {
81- err_protocol ! (
82- "Converting {} {} to {} failed: {}" ,
83- type_info,
84- val,
85- type_name:: <T >( ) ,
86- err
87- )
88- . into ( )
89- } )
90- }
91-
9265fn decode_int_direct < T > ( value : MssqlValueRef < ' _ > ) -> Result < T , BoxDynError >
9366where
9467 T : TryFrom < i64 > + TryFrom < u8 > + TryFrom < i16 > + TryFrom < i32 > ,
@@ -104,12 +77,12 @@ where
10477 let bytes_val = value. as_bytes ( ) ?;
10578
10679 match ty {
107- DataType :: TinyInt => decode_tinyint ( bytes_val, type_info) ,
80+ DataType :: TinyInt => decode_int_bytes ( bytes_val, type_info, u8 :: from_le_bytes ) ,
10881 DataType :: SmallInt => decode_int_bytes ( bytes_val, type_info, i16:: from_le_bytes) ,
10982 DataType :: Int => decode_int_bytes ( bytes_val, type_info, i32:: from_le_bytes) ,
11083 DataType :: BigInt => decode_int_bytes ( bytes_val, type_info, i64:: from_le_bytes) ,
11184 DataType :: IntN => match bytes_val. len ( ) {
112- 1 => decode_tinyint ( bytes_val, type_info) ,
85+ 1 => decode_int_bytes ( bytes_val, type_info, u8 :: from_le_bytes ) ,
11386 2 => decode_int_bytes ( bytes_val, type_info, i16:: from_le_bytes) ,
11487 4 => decode_int_bytes ( bytes_val, type_info, i32:: from_le_bytes) ,
11588 8 => decode_int_bytes ( bytes_val, type_info, i64:: from_le_bytes) ,
0 commit comments