@@ -7356,8 +7356,20 @@ where
7356
7356
impl Writeable for VecDeque < ( Event , Option < EventCompletionAction > ) > {
7357
7357
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
7358
7358
( self . len ( ) as u64 ) . write ( w) ?;
7359
- for elem in self . iter ( ) {
7360
- elem. write ( w) ?;
7359
+ for ( event, action) in self . iter ( ) {
7360
+ event. write ( w) ?;
7361
+ action. write ( w) ?;
7362
+ #[ cfg( debug_assertions) ] {
7363
+ // Events are MaybeReadable, in some cases indicating that they shouldn't actually
7364
+ // be persisted and are regenerated on restart. However, if such an event has a
7365
+ // post-event-handling action we'll write nothing for the event and would have to
7366
+ // either forget the action or fail on deserialization (which we do below). Thus,
7367
+ // check that the event is sane here.
7368
+ let event_encoded = event. encode ( ) ;
7369
+ let event_read: Option < Event > =
7370
+ MaybeReadable :: read ( & mut & event_encoded[ ..] ) . unwrap ( ) ;
7371
+ if action. is_some ( ) { assert ! ( event_read. is_some( ) ) ; }
7372
+ }
7361
7373
}
7362
7374
Ok ( ( ) )
7363
7375
}
@@ -7366,14 +7378,16 @@ impl Readable for VecDeque<(Event, Option<EventCompletionAction>)> {
7366
7378
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
7367
7379
let len: u64 = Readable :: read ( reader) ?;
7368
7380
const MAX_ALLOC_SIZE : u64 = 1024 * 16 ;
7369
- let mut events = VecDeque :: with_capacity ( cmp:: min (
7381
+ let mut events: Self = VecDeque :: with_capacity ( cmp:: min (
7370
7382
MAX_ALLOC_SIZE /mem:: size_of :: < ( events:: Event , Option < EventCompletionAction > ) > ( ) as u64 ,
7371
7383
len) as usize ) ;
7372
7384
for _ in 0 ..len {
7373
7385
let ev_opt = MaybeReadable :: read ( reader) ?;
7374
7386
let action = Readable :: read ( reader) ?;
7375
7387
if let Some ( ev) = ev_opt {
7376
7388
events. push_back ( ( ev, action) ) ;
7389
+ } else if action. is_some ( ) {
7390
+ return Err ( DecodeError :: InvalidValue ) ;
7377
7391
}
7378
7392
}
7379
7393
Ok ( events)
0 commit comments