File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -536,7 +536,7 @@ where
536536
537537#[ cfg( feature = "alloc" ) ]
538538fn flatten_segments < R : message:: ReaderSegments + ?Sized > ( segments : & R ) -> alloc:: vec:: Vec < u8 > {
539- let word_count = compute_serialized_size ( segments) * BYTES_PER_WORD ;
539+ let word_count = compute_serialized_size ( segments) ;
540540 let segment_count = segments. len ( ) ;
541541 let table_size = segment_count / 2 + 1 ;
542542 let mut result = alloc:: vec:: Vec :: with_capacity ( word_count) ;
@@ -667,13 +667,15 @@ where
667667 Ok ( ( ) )
668668}
669669
670+ /// Returns the number of bytes required to serialize the message (including the
671+ /// segment table).
670672fn compute_serialized_size < R : message:: ReaderSegments + ?Sized > ( segments : & R ) -> usize {
671673 // Table size
672674 let len = segments. len ( ) ;
673- let mut size = ( len / 2 ) + 1 ;
675+ let mut size = ( ( len / 2 ) + 1 ) * BYTES_PER_WORD ;
674676 for i in 0 ..len {
675677 let segment = segments. get_segment ( i as u32 ) . unwrap ( ) ;
676- size += segment. len ( ) / BYTES_PER_WORD ;
678+ size += segment. len ( ) ;
677679 }
678680 size
679681}
@@ -687,7 +689,7 @@ pub fn compute_serialized_size_in_words<A>(message: &crate::message::Builder<A>)
687689where
688690 A : crate :: message:: Allocator ,
689691{
690- compute_serialized_size ( & message. get_segments_for_output ( ) )
692+ compute_serialized_size ( & message. get_segments_for_output ( ) ) / BYTES_PER_WORD
691693}
692694
693695#[ cfg( feature = "alloc" ) ]
You can’t perform that action at this time.
0 commit comments