File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,8 +53,8 @@ pub enum MemtrackEventKind {
5353 } ,
5454 Free ,
5555 Realloc {
56- #[ serde( default ) ]
57- old_addr : u64 ,
56+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
57+ old_addr : Option < u64 > ,
5858 size : u64 ,
5959 } ,
6060 Calloc {
@@ -174,4 +174,28 @@ mod tests {
174174
175175 Ok ( ( ) )
176176 }
177+
178+ #[ test]
179+ fn test_deserialize_realloc_compat ( ) -> anyhow:: Result < ( ) > {
180+ // The file contains a single serialized event using the old format without `old_addr`:
181+ // MemtrackEventKind::Realloc { size: 42 }
182+ let buf = include_bytes ! ( "../../testdata/realloc.MemtrackArtifact.msgpack" ) ;
183+ assert_eq ! (
184+ MemtrackArtifact :: decode_streamed( Cursor :: new( buf) ) ?. count( ) ,
185+ 1
186+ ) ;
187+
188+ let event = MemtrackArtifact :: decode_streamed ( Cursor :: new ( buf) ) ?
189+ . next ( )
190+ . unwrap ( ) ;
191+ assert ! ( matches!(
192+ event. kind,
193+ MemtrackEventKind :: Realloc {
194+ old_addr: None ,
195+ size: 42
196+ }
197+ ) ) ;
198+
199+ Ok ( ( ) )
200+ }
177201}
You can’t perform that action at this time.
0 commit comments