package data-encoding

  1. Overview
  2. Docs
val string' : ?length_kind:[ `N | `Uint30 | `Uint16 | `Uint8 ] -> string_json_repr -> int -> string encoding

Encoding of a string whose length does not exceed the specified length.

If length_kind is set, then it is used to encode the length of the string in a header. If length_kind is omitted then the length field uses the smallest fixed-width integer that can accommodate the maximum size - e.g., `Uint8 for very short strings, `Uint16 for longer strings, etc.

Attempting to construct a string with a length that is too long causes an Invalid_argument exception.

  • raises Invalid_argument

    if length_kind is set but it cannot accommodate the specified bound. E.g., Bounded.string' ~length_kind:`Uint8 Hex 1000 raises.

  • raises Invalid_argument

    if specified bound is negative or null.

  • raises Invalid_argument

    if length_kind is unset and the specified bound is larger than 2^30.

val string : int -> string encoding

Same as string' Plain

val bytes' : ?length_kind:[ `N | `Uint30 | `Uint16 | `Uint8 ] -> string_json_repr -> int -> Stdlib.Bytes.t encoding

See string' above.

val bytes : int -> Stdlib.Bytes.t encoding

Same as bytes' Hex

val bigstring : ?length_kind:[ `N | `Uint30 | `Uint16 | `Uint8 ] -> ?string_json_repr:string_json_repr -> int -> bigstring encoding

Same as string but for bigstring.

  • parameter [?string_json_repr]

    defaults to Hex.

  • raises Invalid_argument

    if length_kind is set but it cannot accommodate the specified bound. E.g., Bounded.string' ~length_kind:`Uint8 Hex 1000 raises.

  • raises Invalid_argument

    if specified bound is negative or null.

OCaml

Innovation. Community. Security.