Module Unpack_buffer
A buffer for incremental decoding of an input stream.
An Unpack_buffer.t
is a buffer to which one can feed
strings, and then unpack
from the buffer to produce a queue of values.
module Unpack_one : sig ... end
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.t
include Unpack_buffer__.Import.Invariant.S1 with type 'a t := 'a t
val invariant : 'a Base__.Invariant_intf.inv -> 'a t Base__.Invariant_intf.inv
val create : 'a Unpack_one.t -> 'a t
val create_bin_prot : 'a Bin_prot.Type_class.reader -> 'a t
create_bin_prot reader
returns an unpack buffer that unpacks the "size-prefixed" bin_prot encoding, in which a value is encoded by first writing the length of the bin_prot data as a 64-bit int, and then writing the bin_prot data itself.
val is_empty : _ t -> bool Unpack_buffer__.Import.Or_error.t
is_empty
returnstrue
if all the data fed intot
has been unpacked into values;false
ift
has unconsumed bytes or partially unpacked data.is_empty
returns an error ift
has encountered an unpacking error.
val feed : ?pos:int -> ?len:int -> _ t -> Unpack_buffer__.Import.Bigstring.t -> unit Unpack_buffer__.Import.Or_error.t
feed t buf ?pos ?len
adds the specified substring ofbuf
tot
's buffer. It returns an error ift
has encountered an unpacking error.
val feed_string : ?pos:int -> ?len:int -> _ t -> string -> unit Unpack_buffer__.Import.Or_error.t
val feed_bytes : ?pos:int -> ?len:int -> _ t -> Unpack_buffer__.Import.Bytes.t -> unit Unpack_buffer__.Import.Or_error.t
val unpack_into : 'a t -> 'a Unpack_buffer__.Import.Queue.t -> unit Unpack_buffer__.Import.Or_error.t
unpack_into t q
unpacks all the values that it can fromt
and enqueues them inq
. If there is an unpacking error,unpack_into
returns an error, and subsequentfeed
and unpack operations ont
will return that same error -- i.e. no more data can be fed to or unpacked fromt
.
val unpack_iter : 'a t -> f:('a -> unit) -> unit Unpack_buffer__.Import.Or_error.t
unpack_iter t ~f
unpacks all the values that it can fromt
, callingf
on each value as it's unpacked. If there is an unpacking error (including iff
raises),unpack_iter
returns an error, and subsequentfeed
and unpack operations ont
will return that same error -- i.e., no more data can be fed to or unpacked fromt
.Behavior is unspecified if
f
operates ont
.
val debug : bool Unpack_buffer__.Import.ref
debug
controls whether invariants are checked at each call. Setting this totrue
can make things very slow.