@@ -381,6 +381,7 @@ impl<T> StrictDecode for PhantomData<T> {
381381 fn strict_decode ( _reader : & mut impl TypedRead ) -> Result < Self , DecodeError > { Ok ( default ! ( ) ) }
382382}
383383
384+ // TODO: Provide max length as a trait-level const
384385pub trait StrictSerialize : StrictEncode {
385386 fn strict_serialized_len < const MAX : usize > ( & self ) -> io:: Result < usize > {
386387 let counter = StrictWriter :: counter :: < MAX > ( ) ;
@@ -395,12 +396,17 @@ pub trait StrictSerialize: StrictEncode {
395396 Confined :: < Vec < u8 > , 0 , MAX > :: try_from ( data) . map_err ( SerializeError :: from)
396397 }
397398
399+ fn strict_serialize < const MAX : usize > ( & self , write : impl io:: Write ) -> Result < ( ) , io:: Error > {
400+ let writer = StreamWriter :: new :: < MAX > ( write) ;
401+ self . strict_write ( writer)
402+ }
403+
398404 fn strict_serialize_to_file < const MAX : usize > (
399405 & self ,
400406 path : impl AsRef < std:: path:: Path > ,
401407 ) -> Result < ( ) , SerializeError > {
402408 let file = fs:: File :: create ( path) ?;
403- // TODO: Do FileReader
409+ // TODO: Do FileWriter
404410 let file = StrictWriter :: with ( StreamWriter :: new :: < MAX > ( file) ) ;
405411 self . strict_encode ( file) ?;
406412 Ok ( ( ) )
@@ -420,6 +426,17 @@ pub trait StrictDeserialize: StrictDecode {
420426 Ok ( me)
421427 }
422428
429+ fn strict_deserialize < const MAX : usize > (
430+ mut read : impl io:: Read ,
431+ ) -> Result < Self , DeserializeError > {
432+ let reader = StreamReader :: new :: < MAX > ( & mut read) ;
433+ let me = Self :: strict_read ( reader) ?;
434+ match read. read_exact ( & mut [ 0u8 ; 0 ] ) {
435+ Err ( _) => Ok ( me) ,
436+ Ok ( _) => Err ( DeserializeError :: DataNotEntirelyConsumed ) ,
437+ }
438+ }
439+
423440 fn strict_deserialize_from_file < const MAX : usize > (
424441 path : impl AsRef < std:: path:: Path > ,
425442 ) -> Result < Self , DeserializeError > {
0 commit comments