Module Core_kernel.Unpack_buffer.Unpack_one

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:

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) unpack_result = [
| `Ok of 'a * Core_kernel__.Import.int
| `Not_enough_data of 'partial_unpack * Core_kernel__.Import.int
| `Invalid_data of Error.t
]
type ('a, 'partial_unpack) unpacked = ?⁠partial_unpack:'partial_unpack ‑> ?⁠pos:Core_kernel__.Import.int ‑> ?⁠len:Core_kernel__.Import.int ‑> Bigstring.t ‑> ('a'partial_unpackunpack_result
type 'a t =
| T : ('a_unpacked ‑> 'a t
include Core_kernel__.Import.Monad.S with type t := a t
type 'a t
include Base__.Monad_intf.S_without_syntax with type t := a t
type 'a t
include Base__.Monad_intf.Infix with type t := a t
type 'a t
val (>>=) : 'a t ‑> ('a ‑> 'b t) ‑> 'b t

t >>= f returns a computation that sequences the computations represented by two monad elements. The resulting computation first does t to yield a value v, and then runs the computation returned by f v.

val (>>|) : 'a t ‑> ('a ‑> 'b) ‑> 'b t

t >>| f is t >>= (fun a -> return (f a)).

module Monad_infix : Base__.Monad_intf.Infix with type t := a t
val bind : 'a t ‑> f:('a ‑> 'b t) ‑> 'b t

bind t ~f = t >>= f

val return : 'a ‑> 'a t

return v returns the (trivial) computation that returns v.

val map : 'a t ‑> f:('a ‑> 'b) ‑> 'b t

map t ~f is t >>| f.

val join : 'a t t ‑> 'a t

join t is t >>= (fun t' -> t').

val ignore_m : 'a t ‑> unit t

ignore_m t is map t ~f:(fun _ -> ()). ignore_m used to be called ignore, but we decided that was a bad name, because it shadowed the widely used Pervasives.ignore. Some monads still do let ignore = ignore_m for historical reasons.

val all : 'a t list ‑> 'a list t
val all_unit : unit t list ‑> unit t
val all_ignore : unit t list ‑> unit t
  • Deprecated [since 2018-02] Use [all_unit]
include Base__.Monad_intf.Syntax with type t := a t
type 'a t
module Let_syntax : sig ... end
val create : (?⁠partial_unpack:'p ‑> Bigstring.t ‑> pos:Core_kernel__.Import.int ‑> len:Core_kernel__.Import.int ‑> ('a'punpack_result) ‑> 'a t

create converts an unpacking function that takes required pos and len arguments and converts it to the unpacked form that takes an optional pos and len.

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 bin_blob : Bin_prot.Blob.Opaque.Bigstring.t t

Reads "size-prefixed" bin-blobs, much like create_bin_prot _, but preserves the size information and doesn't deserialize the blob. This allows deserialization to be deferred and the remainder of the sequence can be unpacked if an individual blob can't be deserialized.

val sexp : 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