@@ -78,19 +78,27 @@ mod tests {
7878 Array ,
7979 sizes:: { U4 , U5 } ,
8080 } ;
81+ use bincode:: {
82+ config,
83+ error:: DecodeError ,
84+ serde:: { decode_from_slice, encode_to_vec} ,
85+ } ;
8186
8287 #[ test]
8388 fn deserialize_integer_array ( ) {
84- let serialized = bincode:: serialize ( & INTEGER_ARRAY_EXAMPLE ) . unwrap ( ) ;
85- let deserialized: Array < u64 , U4 > = bincode:: deserialize ( & serialized) . unwrap ( ) ;
89+ let serialized = encode_to_vec ( INTEGER_ARRAY_EXAMPLE , config:: standard ( ) ) . unwrap ( ) ;
90+ let ( deserialized, len) : ( Array < u64 , U4 > , usize ) =
91+ decode_from_slice ( & serialized, config:: standard ( ) ) . unwrap ( ) ;
92+
8693 assert_eq ! ( deserialized, INTEGER_ARRAY_EXAMPLE ) ;
94+ assert_eq ! ( len, serialized. len( ) ) ;
8795 }
8896
8997 #[ test]
9098 fn deserialize_too_short ( ) {
91- let serialized = bincode :: serialize ( & INTEGER_ARRAY_EXAMPLE ) . unwrap ( ) ;
92- let deserialized: Result < Array < u64 , U5 > , bincode :: Error > =
93- bincode :: deserialize ( & serialized) ;
99+ let serialized = encode_to_vec ( INTEGER_ARRAY_EXAMPLE , config :: standard ( ) ) . unwrap ( ) ;
100+ let deserialized: Result < ( Array < u8 , U5 > , usize ) , DecodeError > =
101+ decode_from_slice ( & serialized, config :: standard ( ) ) ;
94102
95103 // TODO(tarcieri): check for more specific error type
96104 assert ! ( deserialized. is_err( ) )
@@ -99,8 +107,11 @@ mod tests {
99107 #[ test]
100108 fn serialize_integer_array ( ) {
101109 let example: Array < u64 , U4 > = Array ( INTEGER_ARRAY_EXAMPLE ) ;
102- let serialized = bincode:: serialize ( & example) . unwrap ( ) ;
103- let deserialized: Array < u64 , U4 > = bincode:: deserialize ( & serialized) . unwrap ( ) ;
110+ let serialized = encode_to_vec ( example, config:: standard ( ) ) . unwrap ( ) ;
111+ let ( deserialized, len) : ( Array < u64 , U4 > , usize ) =
112+ decode_from_slice ( & serialized, config:: standard ( ) ) . unwrap ( ) ;
113+
104114 assert_eq ! ( example, deserialized) ;
115+ assert_eq ! ( len, serialized. len( ) ) ;
105116 }
106117}
0 commit comments