@@ -105,7 +105,7 @@ fn length_encoding_bytes(length: u64) -> Result<usize, Error> {
105
105
}
106
106
107
107
#[ inline( always) ]
108
- pub fn write_length ( content_length : usize ) -> Result < Vec < u8 > , Error > {
108
+ pub fn write_variable_length ( content_length : usize ) -> Result < Vec < u8 > , Error > {
109
109
let len_len = length_encoding_bytes ( content_length. try_into ( ) ?) ?;
110
110
if !cfg ! ( fuzzing) {
111
111
debug_assert ! ( len_len <= 8 , "Invalid vector len_len {len_len}" ) ;
@@ -178,7 +178,7 @@ impl<T: SerializeBytes> SerializeBytes for &[T] {
178
178
// This requires more computations but the other option would be to buffer
179
179
// the entire content, which can end up requiring a lot of memory.
180
180
let content_length = self . iter ( ) . fold ( 0 , |acc, e| acc + e. tls_serialized_len ( ) ) ;
181
- let mut length = write_length ( content_length) ?;
181
+ let mut length = write_variable_length ( content_length) ?;
182
182
let len_len = length. len ( ) ;
183
183
184
184
let mut out = Vec :: with_capacity ( content_length + len_len) ;
@@ -418,7 +418,7 @@ impl<'a> Size for VLByteSlice<'a> {
418
418
}
419
419
420
420
#[ cfg( feature = "std" ) ]
421
- pub ( super ) mod rw {
421
+ pub mod rw {
422
422
use super :: * ;
423
423
use crate :: { Deserialize , Serialize } ;
424
424
@@ -429,7 +429,7 @@ pub(super) mod rw {
429
429
///
430
430
/// The length and number of bytes read are returned.
431
431
#[ inline]
432
- pub fn read_variable_length < R : std:: io:: Read > ( bytes : & mut R ) -> Result < ( usize , usize ) , Error > {
432
+ pub fn read_length < R : std:: io:: Read > ( bytes : & mut R ) -> Result < ( usize , usize ) , Error > {
433
433
// The length is encoded in the first two bits of the first byte.
434
434
let mut len_len_byte = [ 0u8 ; 1 ] ;
435
435
if bytes. read ( & mut len_len_byte) ? == 0 {
@@ -456,7 +456,7 @@ pub(super) mod rw {
456
456
impl < T : Deserialize > Deserialize for Vec < T > {
457
457
#[ inline( always) ]
458
458
fn tls_deserialize < R : std:: io:: Read > ( bytes : & mut R ) -> Result < Self , Error > {
459
- let ( length, len_len) = read_variable_length ( bytes) ?;
459
+ let ( length, len_len) = read_length ( bytes) ?;
460
460
461
461
if length == 0 {
462
462
// An empty vector.
@@ -475,11 +475,11 @@ pub(super) mod rw {
475
475
}
476
476
477
477
#[ inline( always) ]
478
- pub ( super ) fn write_length < W : std:: io:: Write > (
478
+ pub fn write_length < W : std:: io:: Write > (
479
479
writer : & mut W ,
480
480
content_length : usize ,
481
481
) -> Result < usize , Error > {
482
- let buf = super :: write_length ( content_length) ?;
482
+ let buf = super :: write_variable_length ( content_length) ?;
483
483
let buf_len = buf. len ( ) ;
484
484
writer. write_all ( & buf) ?;
485
485
Ok ( buf_len)
@@ -523,9 +523,6 @@ pub(super) mod rw {
523
523
}
524
524
}
525
525
526
- #[ cfg( feature = "std" ) ]
527
- use rw:: * ;
528
-
529
526
/// Read/Write (std) based (de)serialization for [`VLBytes`].
530
527
#[ cfg( feature = "std" ) ]
531
528
mod rw_bytes {
@@ -551,7 +548,7 @@ mod rw_bytes {
551
548
return Err ( Error :: InvalidVectorLength ) ;
552
549
}
553
550
554
- let length_bytes = write_length ( content_length) ?;
551
+ let length_bytes = write_variable_length ( content_length) ?;
555
552
let len_len = length_bytes. len ( ) ;
556
553
writer. write_all ( & length_bytes) ?;
557
554
@@ -577,7 +574,7 @@ mod rw_bytes {
577
574
578
575
impl Deserialize for VLBytes {
579
576
fn tls_deserialize < R : std:: io:: Read > ( bytes : & mut R ) -> Result < Self , Error > {
580
- let ( length, _) = read_variable_length ( bytes) ?;
577
+ let ( length, _) = rw :: read_length ( bytes) ?;
581
578
if length == 0 {
582
579
return Ok ( Self :: new ( vec ! [ ] ) ) ;
583
580
}
0 commit comments