Module Iobuf.Expert

The Expert module is for building efficient out-of-module Iobuf abstractions.

val buf : (__) t -> Core__.Import.Bigstring.t

These accessors will not allocate, and are mainly here to assist in building low-cost syscall wrappers.

One must be careful to avoid writing out of the limits (between lo_min and hi_max) of the buf. Doing so would violate the invariants of the parent Iobuf.

val hi_max : (__) t -> int
val hi : (__) t -> int
val lo : (__) t -> int
val lo_min : (__) t -> int
val set_buf : (__) t -> Core__.Import.Bigstring.t -> unit

These setters directly set fields in t without checking any invariants.

val set_hi_max : (__) t -> int -> unit
val set_hi : (__) t -> int -> unit
val set_lo : (__) t -> int -> unit
val set_lo_min : (__) t -> int -> unit
val to_bigstring_shared : ?⁠pos:int -> ?⁠len:int -> (__) t -> Core__.Import.Bigstring.t

to_bigstring_shared t and to_iobuf_shared t allocate new wrappers around the storage of buf t, relative to t's current bounds.

These operations allow access outside the bounds and limits of t, and without respect to its read/write access. Be careful not to violate t's invariants.

val to_iovec_shared : ?⁠pos:int -> ?⁠len:int -> (__) t -> Core__.Import.Bigstring.t Core.Iobuf_intf.Unix.IOVec.t
val reinitialize_of_bigstring : (__) t -> pos:int -> len:int -> Core__.Import.Bigstring.t -> unit

reinitialize_of_bigstring t bigstring reinitializes t with backing bigstring, and the window and limits specified starting at pos and of length len.

val set_bounds_and_buffer : src:('data_) t -> dst:('dataseek) t -> unit

These versions of set_bounds_and_buffer allow ~src to be read-only. ~dst will be writable through ~src aliases even though the type does not reflect this!

val set_bounds_and_buffer_sub : pos:int -> len:int -> src:('data_) t -> dst:('dataseek) t -> unit
val protect_window : ('rw_) t -> f:(('rwseek) t -> 'a) -> 'a

Similar to protect_window_and_bounds, but does not save/restore the buffer or bounds. Mixing this with functions like set_bounds_and_buffer or narrow is unsafe; you should not modify anyything but the window inside f.

val fillf_float : (Core__.Import.read_writeseek) t -> c_format:string -> float -> [ `Ok | `Truncated | `Format_error ]

fillf_float t ~c_format float attempts to fill a string representation of a float into an iobuf at the current position. The representation is specified by standard C printf formatting codes.

The highest available byte of the window is unusable and will be set to 0 in the case that a properly formatted string would otherwise fully fill the window.

If there is enough room in (window - 1) to format the float as specified then `Ok is returned and the window is advanced past the written bytes.

If there is not enough room in (window - 1) to format as specified then `Truncated is returned.

If C snprintf indicates a format error then `Format_error is returned.

Operation is unsafe if a format code not intended for a double precision float is used (e.g., %s) or if more than one format specifier is provided, etc.