function Bencode.reset to clear a decoder's state

This commit is contained in:
Simon Cruanes 2013-06-13 13:33:26 +02:00
parent 4dd3c63ba5
commit 97451b48a9
2 changed files with 14 additions and 0 deletions

View file

@ -264,6 +264,15 @@ let parse dec s i len =
(* state machine *)
parse_rec dec
let reset dec =
dec.l <- 0;
dec.c <- 0;
dec.i <- 0;
dec.len <- 0;
dec.state <- ParsePartial;
dec.stack <- [];
()
let state dec = dec.state
let rest dec =

View file

@ -79,6 +79,11 @@ val parse : decoder -> string -> int -> int -> parse_result
It can return an error, a value or just [ParsePartial] if
more input is needed *)
val reset : decoder -> unit
(** Reset the decoder to its pristine state, ready to parse something
different. Before that, {! rest} and {! rest_size} can be used
to recover the part of the input that has not been consumed yet. *)
val state : decoder -> parse_result
(** Current state of the decoder *)