package regular

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

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.bigstring) -> ?dump:(Core_kernel.Out_channel.t -> 'a -> unit) -> ?pp:(Stdlib.Format.formatter -> 'a -> unit) -> ?size:('a -> int) -> ?blit_to_string:('a, bytes) copy -> ?blit_to_bigstring:('a, Core_kernel.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.Out_channel.t -> 'a -> unit

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

val to_formatter : 'a t -> Stdlib.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.bigstring

to_bigstring writeable value serializes the value into bigstring data type.

val blit_to_string : 'a t -> bytes -> '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

  • deprecated [since 2018-11] use the blit_to_bytes instead
val blit_to_bytes : 'a t -> bytes -> 'a -> int -> unit

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

val blit_to_bigstring : 'a t -> Core_kernel.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.