@@ -37,29 +37,27 @@ pub struct DecodeContext {
3737 /// How many times we can recurse in the current decode stack before we hit
3838 /// the recursion limit.
3939 ///
40- /// The recursion limit is defined by `RECURSION_LIMIT` and cannot be
41- /// customized. The recursion limit can be ignored by building the Prost
42- /// crate with the `no-recursion-limit` feature.
40+ /// It defaults to 100 and can be changed using `prost_build::recursion_limit`,
41+ /// or it can be disabled entirely using the `no-recursion-limit` feature.
4342 #[ cfg( not( feature = "no-recursion-limit" ) ) ]
44- recurse_count : u32 ,
43+ #[ doc( hidden) ]
44+ pub recurse_count : u32 ,
4545}
4646
47- #[ cfg( not( feature = "no-recursion-limit" ) ) ]
48- impl Default for DecodeContext {
49- #[ inline]
50- fn default ( ) -> DecodeContext {
47+ impl DecodeContext {
48+ #[ allow( unused_variables) ]
49+ pub fn new ( recursion_limit : u32 ) -> DecodeContext {
5150 DecodeContext {
52- recurse_count : crate :: RECURSION_LIMIT ,
51+ #[ cfg( not( feature = "no-recursion-limit" ) ) ]
52+ recurse_count : recursion_limit,
5353 }
5454 }
55- }
5655
57- impl DecodeContext {
5856 /// Call this function before recursively decoding.
5957 ///
6058 /// There is no `exit` function since this function creates a new `DecodeContext`
6159 /// to be used at the next level of recursion. Continue to use the old context
62- // at the previous level of recursion.
60+ /// at the previous level of recursion.
6361 #[ cfg( not( feature = "no-recursion-limit" ) ) ]
6462 #[ inline]
6563 pub ( crate ) fn enter_recursion ( & self ) -> DecodeContext {
@@ -1225,7 +1223,7 @@ mod test {
12251223 wire_type,
12261224 & mut roundtrip_value,
12271225 & mut buf,
1228- DecodeContext :: default ( ) ,
1226+ DecodeContext :: new ( 100 ) ,
12291227 )
12301228 . map_err ( |error| TestCaseError :: fail ( error. to_string ( ) ) ) ?;
12311229
@@ -1297,7 +1295,7 @@ mod test {
12971295 wire_type,
12981296 & mut roundtrip_value,
12991297 & mut buf,
1300- DecodeContext :: default ( ) ,
1298+ DecodeContext :: new ( 100 ) ,
13011299 )
13021300 . map_err ( |error| TestCaseError :: fail ( error. to_string ( ) ) ) ?;
13031301 }
@@ -1316,7 +1314,7 @@ mod test {
13161314 WireType :: LengthDelimited ,
13171315 & mut s,
13181316 & mut & buf[ ..] ,
1319- DecodeContext :: default ( ) ,
1317+ DecodeContext :: new ( 100 ) ,
13201318 ) ;
13211319 r. expect_err ( "must be an error" ) ;
13221320 assert ! ( s. is_empty( ) ) ;
0 commit comments