File tree Expand file tree Collapse file tree 2 files changed +19
-19
lines changed
Expand file tree Collapse file tree 2 files changed +19
-19
lines changed Original file line number Diff line number Diff line change @@ -4,25 +4,16 @@ mod mutation;
44
55use mutation:: Mutation ;
66
7+ // Implement the metadata trait for our mutation
8+ // type. Will will use the standard library for the implementation
9+ // details.
710impl metadata:: MetadataRoundtrip for Mutation {
811 fn encode ( & self ) -> Result < Vec < u8 > , metadata:: MetadataError > {
9- let mut rv = vec ! [ ] ;
10- rv. extend ( self . effect_size . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
11- rv. extend ( self . dominance . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
12- rv. extend ( self . origin_time . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
13- Ok ( rv)
12+ Ok ( bincode:: serialize ( & self ) . unwrap ( ) )
1413 }
1514
1615 fn decode ( md : & [ u8 ] ) -> Result < Self , metadata:: MetadataError > {
17- use std:: convert:: TryInto ;
18- let ( effect_size_bytes, rest) = md. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
19- let ( dominance_bytes, rest) = rest. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
20- let ( origin_time_bytes, _) = rest. split_at ( std:: mem:: size_of :: < i32 > ( ) ) ;
21- Ok ( Self {
22- effect_size : f64:: from_le_bytes ( effect_size_bytes. try_into ( ) . unwrap ( ) ) ,
23- dominance : f64:: from_le_bytes ( dominance_bytes. try_into ( ) . unwrap ( ) ) ,
24- origin_time : i32:: from_le_bytes ( origin_time_bytes. try_into ( ) . unwrap ( ) ) ,
25- } )
16+ Ok ( bincode:: deserialize ( md) . unwrap ( ) )
2617 }
2718}
2819
Original file line number Diff line number Diff line change @@ -4,16 +4,25 @@ mod mutation;
44
55use mutation:: Mutation ;
66
7- // Implement the metadata trait for our mutation
8- // type. Will will use the standard library for the implementation
9- // details.
107impl metadata:: MetadataRoundtrip for Mutation {
118 fn encode ( & self ) -> Result < Vec < u8 > , metadata:: MetadataError > {
12- Ok ( bincode:: serialize ( & self ) . unwrap ( ) )
9+ let mut rv = vec ! [ ] ;
10+ rv. extend ( self . effect_size . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
11+ rv. extend ( self . dominance . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
12+ rv. extend ( self . origin_time . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
13+ Ok ( rv)
1314 }
1415
1516 fn decode ( md : & [ u8 ] ) -> Result < Self , metadata:: MetadataError > {
16- Ok ( bincode:: deserialize ( md) . unwrap ( ) )
17+ use std:: convert:: TryInto ;
18+ let ( effect_size_bytes, rest) = md. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
19+ let ( dominance_bytes, rest) = rest. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
20+ let ( origin_time_bytes, _) = rest. split_at ( std:: mem:: size_of :: < i32 > ( ) ) ;
21+ Ok ( Self {
22+ effect_size : f64:: from_le_bytes ( effect_size_bytes. try_into ( ) . unwrap ( ) ) ,
23+ dominance : f64:: from_le_bytes ( dominance_bytes. try_into ( ) . unwrap ( ) ) ,
24+ origin_time : i32:: from_le_bytes ( origin_time_bytes. try_into ( ) . unwrap ( ) ) ,
25+ } )
1726 }
1827}
1928
You can’t perform that action at this time.
0 commit comments