If unpack_one : ('a, 'partial_unpack) unpack_one
, then unpack_one buf ?pos
?len ?partial_unpack
must unpack at most one value of type 'a
from buf
starting at pos
, and not using more than len
characters. unpack_one
must
returns one the following:
`Ok (value, n)
-- unpacking succeeded and consumed n
bytes, where 0 <= n <=
len
. It is possible to have n = 0
, e.g. for sexp unpacking, which can only tell
it has reached the end of an atom when it encounters the following punctuation
character, which if it is left paren, is the start of the following sexp.`Not_enough_data (p, n)
-- unpacking encountered a valid proper prefix of a
packed value, and consumed n
bytes, where 0 <= n <= len
. p
is a "partial
unpack" that can be supplied to a future call to unpack_one
to continue unpacking.`Invalid_data
-- unpacking encountered an invalidly packed value.A naive unpack_one
that only succeeds on a fully packed value could lead to
quadratic behavior if a packed value's bytes are input using a linear number of
calls to feed
.
type ('a, 'partial_unpack) unpacked
= ?partial_unpack:'partial_unpack ‑> ?pos:Core_kernel__.Import.int ‑> ?len:Core_kernel__.Import.int ‑> Core_kernel.Bigstring.t ‑> [ `Ok of 'a * Core_kernel__.Import.int | `Not_enough_data of 'partial_unpack * Core_kernel__.Import.int | `Invalid_data of Core_kernel.Error.t ]
include Core_kernel__.Import.Monad.S with type a t := a t
include Base__.Monad_intf.S_without_syntax with type a t := a t
type 'a t
A monad is an abstraction of the concept of sequencing of computations. A value of type 'a monad represents a computation that returns a value of type 'a.
include Base__.Monad_intf.Infix with type a t := a t
module Monad_infix : Base__.Monad_intf.Infix with type a t := a t
val create_bin_prot : 'a Bin_prot.Type_class.reader ‑> 'a t
create_bin_prot reader
returns an unpacker that reads 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 data itself. This encoding makes it
trivial to know if enough data is available in the buffer, so there is no need to
represent partially unpacked values, and hence 'partial_unpack = unit
.
val sexp : Core_kernel__.Std_internal.Sexp.t t
Beware that when unpacking sexps, one cannot tell if one is at the end of an atom until one hits punctuation. So, one should always feed a space (" ") to a sexp unpack buffer after feeding a batch of complete sexps, to ensure that the final sexp is unpacked.
val char : Core_kernel__.Import.char t
module type Equal : sig ... end
val expect : 'a t ‑> (module Equal with type t = 'a) ‑> 'a ‑> Core_kernel__.Import.unit t
expect t equal a
returns an unpacker that unpacks using t
and then returns `Ok
if the unpacked value equals a
, or `Invalid_data
otherwise.
val expect_char : Core_kernel__.Import.char ‑> Core_kernel__.Import.unit t
expect_char
is expect char (module Char)
val newline : Core_kernel__.Import.unit t