@@ -32,7 +32,7 @@ pub trait ColumnLevelDecoder {
3232 type Buffer ;
3333
3434 /// Set data for this [`ColumnLevelDecoder`]
35- fn set_data ( & mut self , encoding : Encoding , data : Bytes ) ;
35+ fn set_data ( & mut self , encoding : Encoding , data : Bytes ) -> Result < ( ) > ;
3636}
3737
3838pub trait RepetitionLevelDecoder : ColumnLevelDecoder {
@@ -266,15 +266,15 @@ enum LevelDecoder {
266266}
267267
268268impl LevelDecoder {
269- fn new ( encoding : Encoding , data : Bytes , bit_width : u8 ) -> Self {
269+ fn new ( encoding : Encoding , data : Bytes , bit_width : u8 ) -> Result < Self > {
270270 match encoding {
271271 Encoding :: RLE => {
272272 let mut decoder = RleDecoder :: new ( bit_width) ;
273- decoder. set_data ( data) ;
274- Self :: Rle ( decoder)
273+ decoder. set_data ( data) ? ;
274+ Ok ( Self :: Rle ( decoder) )
275275 }
276276 #[ allow( deprecated) ]
277- Encoding :: BIT_PACKED => Self :: Packed ( BitReader :: new ( data) , bit_width) ,
277+ Encoding :: BIT_PACKED => Ok ( Self :: Packed ( BitReader :: new ( data) , bit_width) ) ,
278278 _ => unreachable ! ( "invalid level encoding: {}" , encoding) ,
279279 }
280280 }
@@ -310,8 +310,9 @@ impl DefinitionLevelDecoderImpl {
310310impl ColumnLevelDecoder for DefinitionLevelDecoderImpl {
311311 type Buffer = Vec < i16 > ;
312312
313- fn set_data ( & mut self , encoding : Encoding , data : Bytes ) {
314- self . decoder = Some ( LevelDecoder :: new ( encoding, data, self . bit_width ) )
313+ fn set_data ( & mut self , encoding : Encoding , data : Bytes ) -> Result < ( ) > {
314+ self . decoder = Some ( LevelDecoder :: new ( encoding, data, self . bit_width ) ?) ;
315+ Ok ( ( ) )
315316 }
316317}
317318
@@ -413,10 +414,11 @@ impl RepetitionLevelDecoderImpl {
413414impl ColumnLevelDecoder for RepetitionLevelDecoderImpl {
414415 type Buffer = Vec < i16 > ;
415416
416- fn set_data ( & mut self , encoding : Encoding , data : Bytes ) {
417- self . decoder = Some ( LevelDecoder :: new ( encoding, data, self . bit_width ) ) ;
417+ fn set_data ( & mut self , encoding : Encoding , data : Bytes ) -> Result < ( ) > {
418+ self . decoder = Some ( LevelDecoder :: new ( encoding, data, self . bit_width ) ? ) ;
418419 self . buffer_len = 0 ;
419420 self . buffer_offset = 0 ;
421+ Ok ( ( ) )
420422 }
421423}
422424
@@ -499,14 +501,14 @@ mod tests {
499501 let data = Bytes :: from ( encoder. consume ( ) ) ;
500502
501503 let mut decoder = RepetitionLevelDecoderImpl :: new ( 1 ) ;
502- decoder. set_data ( Encoding :: RLE , data. clone ( ) ) ;
504+ decoder. set_data ( Encoding :: RLE , data. clone ( ) ) . unwrap ( ) ;
503505 let ( _, levels) = decoder. skip_rep_levels ( 100 , 4 ) . unwrap ( ) ;
504506 assert_eq ! ( levels, 4 ) ;
505507
506508 // The length of the final bit packed run is ambiguous, so without the correct
507509 // levels limit, it will decode zero padding
508510 let mut decoder = RepetitionLevelDecoderImpl :: new ( 1 ) ;
509- decoder. set_data ( Encoding :: RLE , data) ;
511+ decoder. set_data ( Encoding :: RLE , data) . unwrap ( ) ;
510512 let ( _, levels) = decoder. skip_rep_levels ( 100 , 6 ) . unwrap ( ) ;
511513 assert_eq ! ( levels, 6 ) ;
512514 }
@@ -525,7 +527,7 @@ mod tests {
525527 let data = Bytes :: from ( encoder. consume ( ) ) ;
526528
527529 let mut decoder = RepetitionLevelDecoderImpl :: new ( 5 ) ;
528- decoder. set_data ( Encoding :: RLE , data) ;
530+ decoder. set_data ( Encoding :: RLE , data) . unwrap ( ) ;
529531
530532 let total_records = encoded. iter ( ) . filter ( |x| * * x == 0 ) . count ( ) ;
531533 let mut remaining_records = total_records;
0 commit comments