@@ -403,12 +403,26 @@ impl Datum {
403
403
}
404
404
}
405
405
PrimitiveType :: Int => PrimitiveLiteral :: Int ( i32:: from_le_bytes ( bytes. try_into ( ) ?) ) ,
406
- PrimitiveType :: Long => PrimitiveLiteral :: Long ( i64:: from_le_bytes ( bytes. try_into ( ) ?) ) ,
406
+ PrimitiveType :: Long => {
407
+ if bytes. len ( ) == 4 {
408
+ // In the case of an evolved field
409
+ PrimitiveLiteral :: Long ( i32:: from_le_bytes ( bytes. try_into ( ) ?) as i64 )
410
+ } else {
411
+ PrimitiveLiteral :: Long ( i64:: from_le_bytes ( bytes. try_into ( ) ?) )
412
+ }
413
+ }
407
414
PrimitiveType :: Float => {
408
415
PrimitiveLiteral :: Float ( OrderedFloat ( f32:: from_le_bytes ( bytes. try_into ( ) ?) ) )
409
416
}
410
417
PrimitiveType :: Double => {
411
- PrimitiveLiteral :: Double ( OrderedFloat ( f64:: from_le_bytes ( bytes. try_into ( ) ?) ) )
418
+ if bytes. len ( ) == 4 {
419
+ // In the case of an evolved field
420
+ PrimitiveLiteral :: Double ( OrderedFloat (
421
+ f32:: from_le_bytes ( bytes. try_into ( ) ?) as f64
422
+ ) )
423
+ } else {
424
+ PrimitiveLiteral :: Double ( OrderedFloat ( f64:: from_le_bytes ( bytes. try_into ( ) ?) ) )
425
+ }
412
426
}
413
427
PrimitiveType :: Date => PrimitiveLiteral :: Int ( i32:: from_le_bytes ( bytes. try_into ( ) ?) ) ,
414
428
PrimitiveType :: Time => PrimitiveLiteral :: Long ( i64:: from_le_bytes ( bytes. try_into ( ) ?) ) ,
@@ -3169,6 +3183,13 @@ mod tests {
3169
3183
check_avro_bytes_serde ( bytes, Datum :: long ( 32 ) , & PrimitiveType :: Long ) ;
3170
3184
}
3171
3185
3186
+ #[ test]
3187
+ fn avro_bytes_long_from_int ( ) {
3188
+ let bytes = vec ! [ 32u8 , 0u8 , 0u8 , 0u8 ] ;
3189
+
3190
+ check_avro_bytes_serde ( bytes, Datum :: long ( 32 ) , & PrimitiveType :: Long ) ;
3191
+ }
3192
+
3172
3193
#[ test]
3173
3194
fn avro_bytes_float ( ) {
3174
3195
let bytes = vec ! [ 0u8 , 0u8 , 128u8 , 63u8 ] ;
@@ -3183,6 +3204,13 @@ mod tests {
3183
3204
check_avro_bytes_serde ( bytes, Datum :: double ( 1.0 ) , & PrimitiveType :: Double ) ;
3184
3205
}
3185
3206
3207
+ #[ test]
3208
+ fn avro_bytes_double_from_float ( ) {
3209
+ let bytes = vec ! [ 0u8 , 0u8 , 128u8 , 63u8 ] ;
3210
+
3211
+ check_avro_bytes_serde ( bytes, Datum :: double ( 1.0 ) , & PrimitiveType :: Double ) ;
3212
+ }
3213
+
3186
3214
#[ test]
3187
3215
fn avro_bytes_string ( ) {
3188
3216
let bytes = vec ! [ 105u8 , 99u8 , 101u8 , 98u8 , 101u8 , 114u8 , 103u8 ] ;
0 commit comments