package orsetto

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

The class of synchronous emitters, which contains a working slice of octets and optionally raises Failure if the size requirement for any particular emitted value is larger than limit. Objects of this class are constructed by the functions below, e.g. buffer_emitter, channel_emitter, etc.

val mutable slice_ : bytes Cf_slice.t

The working slice.

val mutable cursor_ : int

The cursor position.

val mutable start_ : position

Stream position of slice.

method private work : bytes Cf_slice.t -> unit

Use self#work slice to set slice as the working slice and set cursor_ to the start of slice.

method private advance : int -> unit

A successful emission calls self#advance n to signal that a value was encoded as n octets in the working slice at the cursor position.

The basis implementation is simply cursor_ <- cursor_ + n.

method private incomplete : int -> unit

If emitting a value requires at least n more octets to encode than are currently available in the working slice after the cursor position, the basis implementation of self#expand applies self#incomplete n as necessary to update the working slice and cursor position until the working slice is large enough.

The basis implementation raises Incomplete.

method private allocate : 'v. 'v scheme -> 'v -> int * (bytes -> int -> unit)

To reserve space at the cursor position in the working slice to store v as octets according to s.

To accomplish this it applies the ck function in v with the current position, the working slice and v to obtain the `check` result for the scheme. If n more octets are required, then self#incomplete n is applied and self#allocate s v is applied tail recursively. If n octets are available, then the size and an unsafe write function is returned for the emit method to use.

No exceptions raised in any of the private methods in exr or the functions in s are caught.

method private invalid : 'a. position -> string -> 'a

When an encoding scheme calls the invalid p m function (see above), the emitter catches the internal exception and invokes this method to raise the corresponding Invalid (p, m) accordingly.

method emit : 'v. 'v scheme -> 'v -> unit

Use exr#emit s v to store v as octets according to s at the cursor position in the working slice.

To accomplish this, it first obtains the allocation size n and validates v. In the Fix case, the size is taken from the sz field in s and validation is done by applying the ck function in s. In the Var case, validation is performed and the size is computed by applying the ck function in s. Next, if n > 0, it applies self#allocate n, then applies the wr function, and finally applies self#advance n.

No exceptions raised in any of the private methods in exr or the functions in s are caught.

method position : position

Use exr#position to get the total number of valid octets ever emitted by exr.

OCaml

Innovation. Community. Security.