package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

If unpack_one : ('a, 'state) unpack, then unpack_one ~state ~buf ~pos ~len must unpack at most one value of type 'a from buf starting at pos, and not using more than len characters. unpack_one must return 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 (state, n) -- unpacking encountered a valid proper prefix of a packed value, and consumed n bytes, where 0 <= n <= len. state 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, 'state) unpack_result = [
  1. | `Ok of 'a * int
  2. | `Not_enough_data of 'state * int
  3. | `Invalid_data of Core.Error.t
]
type ('a, 'state) unpack = state:'state -> buf:Core.Bigstring.t -> pos:int -> len:int -> ('a, 'state) unpack_result
type 'a t =
  1. | T : {
    1. initial_state : 'state;
    2. unpack : ('a, 'state) unpack;
    } -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
module Monad_infix : sig ... end
val bind : 'a t -> f:('a -> 'b t) -> 'b t
val return : 'a -> 'a t
val map : 'a t -> f:('a -> 'b) -> 'b t
val join : 'a t t -> 'a t
val ignore_m : 'a t -> unit t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
module Let_syntax : sig ... end
val create : initial_state:'state -> unpack:('a, 'state) unpack -> 'a t
val create_bin_prot : 'a Unpack_buffer__.Import.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 : Unpack_buffer__.Import.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 : Core.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 using t and then returns `Ok if the unpacked value equals a, or `Invalid_data otherwise.

val expect_char : char -> unit t

expect_char is expect char (module Char)

val newline : unit t
OCaml

Innovation. Community. Security.