@@ -59,9 +59,10 @@ impl From<ThriftProtocolError> for ParquetError {
5959 match e {
6060 ThriftProtocolError :: Eof => eof_err ! ( "Unexpected EOF" ) ,
6161 ThriftProtocolError :: IO ( e) => e. into ( ) ,
62- ThriftProtocolError :: InvalidFieldType ( value) => {
63- general_err ! ( "Unexpected struct field type {}" , value)
64- }
62+ ThriftProtocolError :: InvalidFieldType ( value) => match FieldType :: try_from ( value) {
63+ Ok ( fld_type) => general_err ! ( "Unexpected struct field type {:?}" , fld_type) ,
64+ Err ( _) => general_err ! ( "Unexpected struct field type {}" , value) ,
65+ } ,
6566 ThriftProtocolError :: InvalidElementType ( value) => {
6667 general_err ! ( "Unexpected list/set element type {}" , value)
6768 }
@@ -247,11 +248,16 @@ pub(crate) struct FieldIdentifier {
247248 pub ( crate ) field_type : FieldType ,
248249 /// The field's `id`. May be computed from delta or directly decoded.
249250 pub ( crate ) id : i16 ,
250- /// Stores the value for booleans.
251- ///
252- /// Boolean fields store no data, instead the field type is either boolean true, or
253- /// boolean false.
254- pub ( crate ) bool_val : Option < bool > ,
251+ }
252+
253+ impl FieldIdentifier {
254+ pub ( crate ) fn bool_val ( & self ) -> ThriftProtocolResult < bool > {
255+ match self . field_type {
256+ FieldType :: BooleanTrue => Ok ( true ) ,
257+ FieldType :: BooleanFalse => Ok ( false ) ,
258+ _ => Err ( ThriftProtocolError :: InvalidFieldType ( self . field_type as u8 ) ) ,
259+ }
260+ }
255261}
256262
257263/// Struct used to describe a [thrift list].
@@ -360,37 +366,24 @@ pub(crate) trait ThriftCompactInputProtocol<'a> {
360366 let field_type = self . read_byte ( ) ?;
361367 let field_delta = ( field_type & 0xf0 ) >> 4 ;
362368 let field_type = FieldType :: try_from ( field_type & 0xf ) ?;
363- let mut bool_val: Option < bool > = None ;
364369
365- match field_type {
366- FieldType :: Stop => Ok ( FieldIdentifier {
370+ match ( field_type, field_delta ) {
371+ ( FieldType :: Stop , _ ) => Ok ( FieldIdentifier {
367372 field_type : FieldType :: Stop ,
368373 id : 0 ,
369- bool_val,
370374 } ) ,
371- _ => {
372- // special handling for bools
373- if field_type == FieldType :: BooleanFalse {
374- bool_val = Some ( false ) ;
375- } else if field_type == FieldType :: BooleanTrue {
376- bool_val = Some ( true ) ;
377- }
378- let field_id = if field_delta != 0 {
379- last_field_id. checked_add ( field_delta as i16 ) . ok_or (
380- ThriftProtocolError :: FieldDeltaOverflow {
381- field_delta,
382- last_field_id,
383- } ,
384- ) ?
385- } else {
386- self . read_full_field_id ( ) ?
387- } ;
388-
389- Ok ( FieldIdentifier {
390- field_type,
391- id : field_id,
392- bool_val,
393- } )
375+ ( field_type, 0 ) => {
376+ let id = self . read_full_field_id ( ) ?;
377+ Ok ( FieldIdentifier { field_type, id } )
378+ }
379+ ( field_type, field_delta) => {
380+ let id = last_field_id. checked_add ( field_delta as i16 ) . ok_or (
381+ ThriftProtocolError :: FieldDeltaOverflow {
382+ field_delta,
383+ last_field_id,
384+ } ,
385+ ) ?;
386+ Ok ( FieldIdentifier { field_type, id } )
394387 }
395388 }
396389 }
0 commit comments