package core_kernel

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

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

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:

type 'a t
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.t
include Base.Invariant.S1 with type 'a t := 'a t
val invariant : ('a -> unit) -> 'a t -> unit
val create : 'a Unpack_one.t -> 'a t
val create_unpacked : ?partial_unpack:'partial_unpack -> ('a, 'partial_unpack) Unpack_one.unpacked -> '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 -> Base.Bool.t Or_error.t

is_empty t returns true if t has no unconsumed bytes, and false if it does. is_empty returns an error if t has encountered an unpacking error.

val feed : ?pos:Base.Int.t -> ?len:Base.Int.t -> _ t -> Bigstring.t -> Base.Unit.t Or_error.t

feed t buf ?pos ?len adds the specified substring of buf to t's buffer. It returns an error if t has encountered an unpacking error.

val feed_string : ?pos:Base.Int.t -> ?len:Base.Int.t -> _ t -> Base.String.t -> Base.Unit.t Or_error.t
val feed_bytes : ?pos:Base.Int.t -> ?len:Base.Int.t -> _ t -> Bytes.t -> Base.Unit.t Or_error.t
val unpack_into : 'a t -> 'a Queue.t -> Base.Unit.t Or_error.t

unpack_into t q unpacks all the values that it can from t and enqueues them in q. If there is an unpacking error, unpack_into returns an error, and subsequent feed and unpack operations on t will return that same error -- i.e. no more data can be fed to or unpacked from t.

val unpack_iter : 'a t -> f:('a -> Base.Unit.t) -> Base.Unit.t Or_error.t

unpack_iter t ~f unpacks all the values that it can from t, calling f on each value as it's unpacked. If there is an unpacking error (including if f raises), unpack_iter returns an error, and subsequent feed and unpack operations on t will return that same error -- i.e., no more data can be fed to or unpacked from t.

Behavior is unspecified if f operates on t.

val debug : Base.Bool.t Pervasives.ref

debug controls whether invariants are checked at each call. Setting this to true can make things very slow.

OCaml

Innovation. Community. Security.