package regular

  1. Overview
  2. Docs

Write typeclass.

Defines a class of writeable (serializable) values. See module Read for more information concerning when and why to use this module.

type 'a t = 'a writer

a writer type class

val create : ?to_bytes:('a -> bytes) -> ?to_bigstring:('a -> Core_kernel.Std.bigstring) -> ?dump:(Core_kernel.Std.out_channel -> 'a -> unit) -> ?pp:(Format.formatter -> 'a -> unit) -> ?size:('a -> int) -> ?blit_to_string:('a, string) copy -> ?blit_to_bigstring:('a, Core_kernel.Std.bigstring) copy -> unit -> 'a t

create <minimal-implementation> creates a writable instance from a provided minimal implementation.

The minimal implementation is either of:

  • to_bytes;
  • to_bigstring;
  • pp.
val size : 'a t -> 'a -> int

size writebale value returns a size in bytes that writeable will use to write value

val to_channel : 'a t -> Core_kernel.Std.out_channel -> 'a -> unit

to_channel writeable out value writes the writable value into the channel chan

val to_formatter : 'a t -> Format.formatter -> 'a -> unit

to_formatter writeable ppf value outputs the value into the formatter ppf

val to_bytes : 'a t -> 'a -> bytes

to_bytes writeable value serializes the value into bytes data type.

val to_bigstring : 'a t -> 'a -> Core_kernel.Std.bigstring

to_bigstring writeable value serializes the value into bigstring data type.

val blit_to_string : 'a t -> string -> 'a -> int -> unit

blit_to_string writeable buf value pos copies a serialized representation of the value into existing string buf, starting from the given position. It is undefined behavior, if the value doesn't fit into the string buf

val blit_to_bigstring : 'a t -> Core_kernel.Std.bigstring -> 'a -> int -> unit

blit_to_bigstring writeable buf value pos copies a serialized representation of the value into existing bigstring buf, starting from the given position. It is undefined behavior, if the value doesn't fit into the string buf

OCaml

Innovation. Community. Security.