@@ -21,7 +21,6 @@ use crate::{
2121} ;
2222
2323/// State machine for decoding DBN with bring your own I/O.
24- #[ derive( Debug ) ]
2524pub struct DbnFsm {
2625 input_dbn_version : Option < u8 > ,
2726 upgrade_policy : VersionUpgradePolicy ,
@@ -31,6 +30,23 @@ pub struct DbnFsm {
3130 compat_buffer : oval:: Buffer ,
3231}
3332
33+ impl std:: fmt:: Debug for DbnFsm {
34+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
35+ let dbg_available_data = self . buffer . available_data ( ) . min ( MAX_RECORD_LEN ) ;
36+ f. debug_struct ( "DbnFsm" )
37+ . field ( "input_dbn_version" , & self . input_dbn_version )
38+ . field ( "upgrade_policy" , & self . upgrade_policy )
39+ . field ( "ts_out" , & self . ts_out )
40+ . field ( "state" , & self . state )
41+ . field (
42+ "buffer_available_data" ,
43+ & & self . buffer . data ( ) [ ..dbg_available_data] ,
44+ )
45+ . field ( "compat_buffer_capacity" , & self . compat_buffer . capacity ( ) )
46+ . finish_non_exhaustive ( )
47+ }
48+ }
49+
3450#[ derive( Debug , Default ) ]
3551enum State {
3652 #[ default]
@@ -386,10 +402,7 @@ impl DbnFsm {
386402 let mut compat_bytes = 0 ;
387403 let mut remaining_compat = self . compat_buffer . space ( ) ;
388404 let mut expand_compat = false ;
389- while rec_ref_buf. has_capacity ( record_count) {
390- if read_bytes >= self . buffer . available_data ( ) {
391- break ;
392- }
405+ while rec_ref_buf. has_capacity ( record_count) && read_bytes < self . buffer . available_data ( ) {
393406 let remaining_data = & self . buffer . data ( ) [ read_bytes..] ;
394407
395408 let length = remaining_data[ 0 ] as usize * RecordHeader :: LENGTH_MULTIPLIER ;
@@ -463,6 +476,9 @@ impl DbnFsm {
463476 "invalid DBN metadata. Metadata length shorter than fixed length." ,
464477 ) ) ;
465478 }
479+ if self . upgrade_policy . is_upgrade_situation ( version) && self . compat_buffer . capacity ( ) == 0 {
480+ self . double_compat_buffer ( ) ;
481+ }
466482 self . state = State :: Metadata { length } ;
467483 self . buffer . consume_noshift ( Self :: METADATA_PRELUDE_LEN ) ;
468484 self . buffer
0 commit comments