Module Unpack_buffer.Unpack_one
type ('a, 'state) unpack_result
=[
|
`Ok of 'a * int
|
`Not_enough_data of 'state * int
|
`Invalid_data of Unpack_buffer__.Import.Error.t
]
type ('a, 'state) unpack
= state:'state -> buf:Unpack_buffer__.Import.Bigstring.t -> pos:int -> len:int -> ('a, 'state) unpack_result
type 'a t
=
|
T :
{
initial_state : 'state;
unpack : ('a, 'state) unpack;
}
-> 'a t
include Unpack_buffer__.Import.Monad.S with type 'a t := 'a t
include Base__.Monad_intf.S_without_syntax with type 'a t := 'a t
module Monad_infix : Base__.Monad_intf.Infix with type 'a t := 'a t
val return : 'a -> 'a t
return v
returns the (trivial) computation that returns v.
val ignore_m : 'a t -> unit t
ignore_m t
ismap t ~f:(fun _ -> ())
.ignore_m
used to be calledignore
, but we decided that was a bad name, because it shadowed the widely usedCaml.ignore
. Some monads still dolet ignore = ignore_m
for historical reasons.
val create : initial_state:'state -> unpack:('a, 'state) unpack -> '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.
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 : Unpack_buffer__.Import.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 : char t
module type Equal = sig ... end
val expect : 'a t -> (module Equal with type t = 'a) -> 'a -> unit t
expect t equal a
returns an unpacker that unpacks usingt
and then returns`Ok
if the unpacked value equalsa
, or`Invalid_data
otherwise.
val expect_char : char -> unit t
expect_char
isexpect char (module Char)
val newline : unit t