@@ -10,7 +10,7 @@ use crate::{Utf8String, Value};
1010// See https://github.com/3Hren/msgpack-rust/issues/151
1111const PREALLOC_MAX : usize = 64 * 1024 ; // 64 KiB
1212
13- fn read_array_data < R : Read > ( rd : & mut R , mut len : usize , depth : usize ) -> Result < Vec < Value > , Error > {
13+ fn read_array_data < R : Read > ( rd : & mut R , mut len : usize , depth : u16 ) -> Result < Vec < Value > , Error > {
1414 let depth = super :: decrement_depth ( depth) ?;
1515
1616 // Note: Do not preallocate a Vec of size `len`.
@@ -25,7 +25,7 @@ fn read_array_data<R: Read>(rd: &mut R, mut len: usize, depth: usize) -> Result<
2525 Ok ( vec)
2626}
2727
28- fn read_map_data < R : Read > ( rd : & mut R , mut len : usize , depth : usize ) -> Result < Vec < ( Value , Value ) > , Error > {
28+ fn read_map_data < R : Read > ( rd : & mut R , mut len : usize , depth : u16 ) -> Result < Vec < ( Value , Value ) > , Error > {
2929 let depth = super :: decrement_depth ( depth) ?;
3030
3131 // Note: Do not preallocate a Vec of size `len`.
@@ -40,7 +40,7 @@ fn read_map_data<R: Read>(rd: &mut R, mut len: usize, depth: usize) -> Result<Ve
4040 Ok ( vec)
4141}
4242
43- fn read_str_data < R : Read > ( rd : & mut R , len : usize , depth : usize ) -> Result < Utf8String , Error > {
43+ fn read_str_data < R : Read > ( rd : & mut R , len : usize , depth : u16 ) -> Result < Utf8String , Error > {
4444 let depth = super :: decrement_depth ( depth) ?;
4545
4646 match String :: from_utf8 ( read_bin_data ( rd, len, depth) ?) {
@@ -55,7 +55,7 @@ fn read_str_data<R: Read>(rd: &mut R, len: usize, depth: usize) -> Result<Utf8St
5555 }
5656}
5757
58- fn read_bin_data < R : Read > ( rd : & mut R , len : usize , depth : usize ) -> Result < Vec < u8 > , Error > {
58+ fn read_bin_data < R : Read > ( rd : & mut R , len : usize , depth : u16 ) -> Result < Vec < u8 > , Error > {
5959 let _depth = super :: decrement_depth ( depth) ?;
6060
6161 let mut buf = Vec :: with_capacity ( min ( len, PREALLOC_MAX ) ) ;
@@ -70,7 +70,7 @@ fn read_bin_data<R: Read>(rd: &mut R, len: usize, depth: usize) -> Result<Vec<u8
7070 Ok ( buf)
7171}
7272
73- fn read_ext_body < R : Read > ( rd : & mut R , len : usize , depth : usize ) -> Result < ( i8 , Vec < u8 > ) , Error > {
73+ fn read_ext_body < R : Read > ( rd : & mut R , len : usize , depth : u16 ) -> Result < ( i8 , Vec < u8 > ) , Error > {
7474 let depth = super :: decrement_depth ( depth) ?;
7575
7676 let ty = rd. read_data_i8 ( ) ?;
@@ -79,7 +79,8 @@ fn read_ext_body<R: Read>(rd: &mut R, len: usize, depth: usize) -> Result<(i8, V
7979 Ok ( ( ty, vec) )
8080}
8181
82- fn read_value_inner < R > ( rd : & mut R , depth : usize ) -> Result < Value , Error > where R : Read {
82+ #[ inline( never) ]
83+ fn read_value_inner < R > ( rd : & mut R , depth : u16 ) -> Result < Value , Error > where R : Read {
8384 let depth = super :: decrement_depth ( depth) ?;
8485 let val = match read_marker ( rd) ? {
8586 Marker :: Null => Value :: Nil ,
@@ -216,11 +217,11 @@ fn read_value_inner<R>(rd: &mut R, depth: usize) -> Result<Value, Error> where R
216217/// [`Error::DepthLimitExceeded`] is returned if this function recurses
217218/// [`MAX_DEPTH`](super::MAX_DEPTH) times. To configure the maximum recursion depth, use
218219/// [`read_value_with_max_depth`] instead.
219- #[ inline( never ) ]
220+ #[ inline]
220221pub fn read_value < R > ( rd : & mut R ) -> Result < Value , Error >
221222 where R : Read
222223{
223- read_value_inner ( rd, super :: MAX_DEPTH )
224+ read_value_inner ( rd, super :: MAX_DEPTH as _ )
224225}
225226
226227/// Attempts to read bytes from the given reader and interpret them as a [`Value`].
@@ -234,9 +235,9 @@ pub fn read_value<R>(rd: &mut R) -> Result<Value, Error>
234235/// [`Error::DepthLimitExceeded`] is returned if this function recurses
235236/// `max_depth` times. If the default [`MAX_DEPTH`](super::MAX_DEPTH) is sufficient or you do not
236237/// need recursion depth checking for your data, consider using [`read_value`] instead.
237- #[ inline( never ) ]
238+ #[ inline]
238239pub fn read_value_with_max_depth < R > ( rd : & mut R , max_depth : usize ) -> Result < Value , Error >
239240 where R : Read
240241{
241- read_value_inner ( rd, max_depth)
242+ read_value_inner ( rd, max_depth. min ( u16 :: MAX as usize ) as u16 )
242243}
0 commit comments