2581 lines
30 KiB
HTML
2581 lines
30 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Bytes</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Bytes</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Bytes - Byte sequence operations.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Bytes
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Bytes</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Byte sequence operations.
|
|
<P>
|
|
A byte sequence is a mutable data structure that contains a
|
|
fixed-length sequence of bytes. Each byte can be indexed in
|
|
constant time for reading or writing.
|
|
<P>
|
|
Given a byte sequence
|
|
<B>s</B>
|
|
|
|
of length
|
|
<B>l</B>
|
|
|
|
, we can access each of the
|
|
<B>l</B>
|
|
|
|
bytes of
|
|
<B>s</B>
|
|
|
|
via its index in the sequence. Indexes start at
|
|
<B>0</B>
|
|
|
|
, and we will call an index valid in
|
|
<B>s</B>
|
|
|
|
if it falls within the
|
|
range
|
|
<B>[0...l-1]</B>
|
|
|
|
(inclusive). A position is the point between two
|
|
bytes or at the beginning or end of the sequence. We call a
|
|
position valid in
|
|
<B>s</B>
|
|
|
|
if it falls within the range
|
|
<B>[0...l]</B>
|
|
|
|
(inclusive). Note that the byte at index
|
|
<B>n</B>
|
|
|
|
is between positions
|
|
<B>n</B>
|
|
|
|
and
|
|
<B>n+1</B>
|
|
|
|
.
|
|
<P>
|
|
Two parameters
|
|
<B>start</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
are said to designate a valid
|
|
range of
|
|
<B>s</B>
|
|
|
|
if
|
|
<B>len >= 0</B>
|
|
|
|
and
|
|
<B>start</B>
|
|
|
|
and
|
|
<B>start+len</B>
|
|
|
|
are valid
|
|
positions in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
Byte sequences can be modified in place, for instance via the
|
|
<B>set</B>
|
|
|
|
and
|
|
<B>blit</B>
|
|
|
|
functions described below. See also strings (module
|
|
<B>String</B>
|
|
|
|
), which are almost the same data structure, but cannot be
|
|
modified in place.
|
|
<P>
|
|
Bytes are represented by the OCaml type
|
|
<B>char</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val length </I>
|
|
|
|
:
|
|
<B>bytes -> int</B>
|
|
|
|
<P>
|
|
Return the length (number of bytes) of the argument.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get s n</B>
|
|
|
|
returns the byte at index
|
|
<B>n</B>
|
|
|
|
in argument
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>n</B>
|
|
|
|
is not a valid index in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set s n c</B>
|
|
|
|
modifies
|
|
<B>s</B>
|
|
|
|
in place, replacing the byte at index
|
|
<B>n</B>
|
|
|
|
with
|
|
<B>c</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>n</B>
|
|
|
|
is not a valid index in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val create </I>
|
|
|
|
:
|
|
<B>int -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>create n</B>
|
|
|
|
returns a new byte sequence of length
|
|
<B>n</B>
|
|
|
|
. The
|
|
sequence is uninitialized and contains arbitrary bytes.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>n < 0</B>
|
|
|
|
or
|
|
<B>n > </B>
|
|
|
|
<B>Sys.max_string_length</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val make </I>
|
|
|
|
:
|
|
<B>int -> char -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>make n c</B>
|
|
|
|
returns a new byte sequence of length
|
|
<B>n</B>
|
|
|
|
, filled with
|
|
the byte
|
|
<B>c</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>n < 0</B>
|
|
|
|
or
|
|
<B>n > </B>
|
|
|
|
<B>Sys.max_string_length</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val init </I>
|
|
|
|
:
|
|
<B>int -> (int -> char) -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>Bytes.init n f</B>
|
|
|
|
returns a fresh byte sequence of length
|
|
<B>n</B>
|
|
|
|
, with
|
|
character
|
|
<B>i</B>
|
|
|
|
initialized to the result of
|
|
<B>f i</B>
|
|
|
|
(in increasing
|
|
index order).
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>n < 0</B>
|
|
|
|
or
|
|
<B>n > </B>
|
|
|
|
<B>Sys.max_string_length</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val empty </I>
|
|
|
|
:
|
|
<B>bytes</B>
|
|
|
|
<P>
|
|
A byte sequence of size 0.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val copy </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
Return a new byte sequence that contains the same bytes as the
|
|
argument.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val of_string </I>
|
|
|
|
:
|
|
<B>string -> bytes</B>
|
|
|
|
<P>
|
|
Return a new byte sequence that contains the same bytes as the
|
|
given string.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val to_string </I>
|
|
|
|
:
|
|
<B>bytes -> string</B>
|
|
|
|
<P>
|
|
Return a new string that contains the same bytes as the given byte
|
|
sequence.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sub </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>sub s start len</B>
|
|
|
|
returns a new byte sequence of length
|
|
<B>len</B>
|
|
|
|
,
|
|
containing the subsequence of
|
|
<B>s</B>
|
|
|
|
that starts at position
|
|
<B>start</B>
|
|
|
|
and has length
|
|
<B>len</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>start</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate a
|
|
valid range of
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sub_string </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> string</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>sub</B>
|
|
|
|
but return a string instead of a byte sequence.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val extend </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>extend s left right</B>
|
|
|
|
returns a new byte sequence that contains
|
|
the bytes of
|
|
<B>s</B>
|
|
|
|
, with
|
|
<B>left</B>
|
|
|
|
uninitialized bytes prepended and
|
|
<B>right</B>
|
|
|
|
uninitialized bytes appended to it. If
|
|
<B>left</B>
|
|
|
|
or
|
|
<B>right</B>
|
|
|
|
is negative, then bytes are removed (instead of appended) from
|
|
the corresponding side of
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if the result length is negative or
|
|
longer than
|
|
<B>Sys.max_string_length</B>
|
|
|
|
bytes.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fill </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> char -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>fill s start len c</B>
|
|
|
|
modifies
|
|
<B>s</B>
|
|
|
|
in place, replacing
|
|
<B>len</B>
|
|
|
|
characters with
|
|
<B>c</B>
|
|
|
|
, starting at
|
|
<B>start</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>start</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate a
|
|
valid range of
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val blit </I>
|
|
|
|
:
|
|
<B>bytes -> int -> bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>blit src srcoff dst dstoff len</B>
|
|
|
|
copies
|
|
<B>len</B>
|
|
|
|
bytes from sequence
|
|
<B>src</B>
|
|
|
|
, starting at index
|
|
<B>srcoff</B>
|
|
|
|
, to sequence
|
|
<B>dst</B>
|
|
|
|
, starting at
|
|
index
|
|
<B>dstoff</B>
|
|
|
|
. It works correctly even if
|
|
<B>src</B>
|
|
|
|
and
|
|
<B>dst</B>
|
|
|
|
are the
|
|
same byte sequence, and the source and destination intervals
|
|
overlap.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>srcoff</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not
|
|
designate a valid range of
|
|
<B>src</B>
|
|
|
|
, or if
|
|
<B>dstoff</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate a valid range of
|
|
<B>dst</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val blit_string </I>
|
|
|
|
:
|
|
<B>string -> int -> bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>blit src srcoff dst dstoff len</B>
|
|
|
|
copies
|
|
<B>len</B>
|
|
|
|
bytes from string
|
|
<B>src</B>
|
|
|
|
, starting at index
|
|
<B>srcoff</B>
|
|
|
|
, to byte sequence
|
|
<B>dst</B>
|
|
|
|
,
|
|
starting at index
|
|
<B>dstoff</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>srcoff</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not
|
|
designate a valid range of
|
|
<B>src</B>
|
|
|
|
, or if
|
|
<B>dstoff</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate a valid range of
|
|
<B>dst</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val concat </I>
|
|
|
|
:
|
|
<B>bytes -> bytes list -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>concat sep sl</B>
|
|
|
|
concatenates the list of byte sequences
|
|
<B>sl</B>
|
|
|
|
,
|
|
inserting the separator byte sequence
|
|
<B>sep</B>
|
|
|
|
between each, and
|
|
returns the result as a new byte sequence.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if the result is longer than
|
|
<B>Sys.max_string_length</B>
|
|
|
|
bytes.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val cat </I>
|
|
|
|
:
|
|
<B>bytes -> bytes -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>cat s1 s2</B>
|
|
|
|
concatenates
|
|
<B>s1</B>
|
|
|
|
and
|
|
<B>s2</B>
|
|
|
|
and returns the result
|
|
as new byte sequence.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if the result is longer than
|
|
<B>Sys.max_string_length</B>
|
|
|
|
bytes.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val iter </I>
|
|
|
|
:
|
|
<B>(char -> unit) -> bytes -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>iter f s</B>
|
|
|
|
applies function
|
|
<B>f</B>
|
|
|
|
in turn to all the bytes of
|
|
<B>s</B>
|
|
|
|
.
|
|
It is equivalent to
|
|
<B>f (get s 0); f (get s 1); ...; f (get s</B>
|
|
|
|
<B>(length s - 1)); ()</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val iteri </I>
|
|
|
|
:
|
|
<B>(int -> char -> unit) -> bytes -> unit</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>Bytes.iter</B>
|
|
|
|
, but the function is applied to the index of
|
|
the byte as first argument and the byte itself as second
|
|
argument.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val map </I>
|
|
|
|
:
|
|
<B>(char -> char) -> bytes -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>map f s</B>
|
|
|
|
applies function
|
|
<B>f</B>
|
|
|
|
in turn to all the bytes of
|
|
<B>s</B>
|
|
|
|
(in increasing index order) and stores the resulting bytes in
|
|
a new sequence that is returned as the result.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val mapi </I>
|
|
|
|
:
|
|
<B>(int -> char -> char) -> bytes -> bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>mapi f s</B>
|
|
|
|
calls
|
|
<B>f</B>
|
|
|
|
with each character of
|
|
<B>s</B>
|
|
|
|
and its
|
|
index (in increasing index order) and stores the resulting bytes
|
|
in a new sequence that is returned as the result.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val trim </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
Return a copy of the argument, without leading and trailing
|
|
whitespace. The bytes regarded as whitespace are the ASCII
|
|
characters
|
|
<B>' '</B>
|
|
|
|
,
|
|
<B>'\012'</B>
|
|
|
|
,
|
|
<B>'\n'</B>
|
|
|
|
,
|
|
<B>'\r'</B>
|
|
|
|
, and
|
|
<B>'\t'</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val escaped </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
Return a copy of the argument, with special characters represented
|
|
by escape sequences, following the lexical conventions of OCaml.
|
|
All characters outside the ASCII printable range (32..126) are
|
|
escaped, as well as backslash and double-quote.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if the result is longer than
|
|
<B>Sys.max_string_length</B>
|
|
|
|
bytes.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val index </I>
|
|
|
|
:
|
|
<B>bytes -> char -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>index s c</B>
|
|
|
|
returns the index of the first occurrence of byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Not_found</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not occur in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val index_opt </I>
|
|
|
|
:
|
|
<B>bytes -> char -> int option</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>index_opt s c</B>
|
|
|
|
returns the index of the first occurrence of byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
or
|
|
<B>None</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not occur in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rindex </I>
|
|
|
|
:
|
|
<B>bytes -> char -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rindex s c</B>
|
|
|
|
returns the index of the last occurrence of byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Not_found</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not occur in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rindex_opt </I>
|
|
|
|
:
|
|
<B>bytes -> char -> int option</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rindex_opt s c</B>
|
|
|
|
returns the index of the last occurrence of byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
or
|
|
<B>None</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not occur in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val index_from </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>index_from s i c</B>
|
|
|
|
returns the index of the first occurrence of
|
|
byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
after position
|
|
<B>i</B>
|
|
|
|
.
|
|
<B>Bytes.index s c</B>
|
|
|
|
is
|
|
equivalent to
|
|
<B>Bytes.index_from s 0 c</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>i</B>
|
|
|
|
is not a valid position in
|
|
<B>s</B>
|
|
|
|
.
|
|
Raise
|
|
<B>Not_found</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not occur in
|
|
<B>s</B>
|
|
|
|
after position
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val index_from_opt </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char -> int option</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>index_from _opts i c</B>
|
|
|
|
returns the index of the first occurrence of
|
|
byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
after position
|
|
<B>i</B>
|
|
|
|
or
|
|
<B>None</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not occur in
|
|
<B>s</B>
|
|
|
|
after position
|
|
<B>i</B>
|
|
|
|
.
|
|
<B>Bytes.index_opt s c</B>
|
|
|
|
is equivalent to
|
|
<B>Bytes.index_from_opt s 0 c</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>i</B>
|
|
|
|
is not a valid position in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rindex_from </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rindex_from s i c</B>
|
|
|
|
returns the index of the last occurrence of
|
|
byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
before position
|
|
<B>i+1</B>
|
|
|
|
.
|
|
<B>rindex s c</B>
|
|
|
|
is equivalent
|
|
to
|
|
<B>rindex_from s (Bytes.length s - 1) c</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>i+1</B>
|
|
|
|
is not a valid position in
|
|
<B>s</B>
|
|
|
|
.
|
|
Raise
|
|
<B>Not_found</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not occur in
|
|
<B>s</B>
|
|
|
|
before position
|
|
<B>i+1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rindex_from_opt </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char -> int option</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rindex_from_opt s i c</B>
|
|
|
|
returns the index of the last occurrence
|
|
of byte
|
|
<B>c</B>
|
|
|
|
in
|
|
<B>s</B>
|
|
|
|
before position
|
|
<B>i+1</B>
|
|
|
|
or
|
|
<B>None</B>
|
|
|
|
if
|
|
<B>c</B>
|
|
|
|
does not
|
|
occur in
|
|
<B>s</B>
|
|
|
|
before position
|
|
<B>i+1</B>
|
|
|
|
.
|
|
<B>rindex_opt s c</B>
|
|
|
|
is equivalent to
|
|
<B>rindex_from s (Bytes.length s - 1) c</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>i+1</B>
|
|
|
|
is not a valid position in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val contains </I>
|
|
|
|
:
|
|
<B>bytes -> char -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>contains s c</B>
|
|
|
|
tests if byte
|
|
<B>c</B>
|
|
|
|
appears in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val contains_from </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>contains_from s start c</B>
|
|
|
|
tests if byte
|
|
<B>c</B>
|
|
|
|
appears in
|
|
<B>s</B>
|
|
|
|
after
|
|
position
|
|
<B>start</B>
|
|
|
|
.
|
|
<B>contains s c</B>
|
|
|
|
is equivalent to
|
|
<B>contains_from</B>
|
|
|
|
<B>s 0 c</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>start</B>
|
|
|
|
is not a valid position in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rcontains_from </I>
|
|
|
|
:
|
|
<B>bytes -> int -> char -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rcontains_from s stop c</B>
|
|
|
|
tests if byte
|
|
<B>c</B>
|
|
|
|
appears in
|
|
<B>s</B>
|
|
|
|
before
|
|
position
|
|
<B>stop+1</B>
|
|
|
|
.
|
|
<P>
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>stop < 0</B>
|
|
|
|
or
|
|
<B>stop+1</B>
|
|
|
|
is not a valid
|
|
position in
|
|
<B>s</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val uppercase </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
<B>Deprecated.</B>
|
|
|
|
Functions operating on Latin-1 character set are deprecated.
|
|
<P>
|
|
<P>
|
|
Return a copy of the argument, with all lowercase letters
|
|
translated to uppercase, including accented letters of the ISO
|
|
Latin-1 (8859-1) character set.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val lowercase </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
<B>Deprecated.</B>
|
|
|
|
Functions operating on Latin-1 character set are deprecated.
|
|
<P>
|
|
<P>
|
|
Return a copy of the argument, with all uppercase letters
|
|
translated to lowercase, including accented letters of the ISO
|
|
Latin-1 (8859-1) character set.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val capitalize </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
<B>Deprecated.</B>
|
|
|
|
Functions operating on Latin-1 character set are deprecated.
|
|
<P>
|
|
<P>
|
|
Return a copy of the argument, with the first character set to uppercase,
|
|
using the ISO Latin-1 (8859-1) character set..
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val uncapitalize </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
<B>Deprecated.</B>
|
|
|
|
Functions operating on Latin-1 character set are deprecated.
|
|
<P>
|
|
<P>
|
|
Return a copy of the argument, with the first character set to lowercase,
|
|
using the ISO Latin-1 (8859-1) character set..
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val uppercase_ascii </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
Return a copy of the argument, with all lowercase letters
|
|
translated to uppercase, using the US-ASCII character set.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val lowercase_ascii </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
Return a copy of the argument, with all uppercase letters
|
|
translated to lowercase, using the US-ASCII character set.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val capitalize_ascii </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
Return a copy of the argument, with the first character set to uppercase,
|
|
using the US-ASCII character set.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val uncapitalize_ascii </I>
|
|
|
|
:
|
|
<B>bytes -> bytes</B>
|
|
|
|
<P>
|
|
Return a copy of the argument, with the first character set to lowercase,
|
|
using the US-ASCII character set.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03.0
|
|
<P>
|
|
<P>
|
|
<I>type t </I>
|
|
|
|
=
|
|
<B>bytes</B>
|
|
|
|
<P>
|
|
<P>
|
|
An alias for the type of byte sequences.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val compare </I>
|
|
|
|
:
|
|
<B>t -> t -> int</B>
|
|
|
|
<P>
|
|
The comparison function for byte sequences, with the same
|
|
specification as
|
|
<B>compare</B>
|
|
|
|
. Along with the type
|
|
<B>t</B>
|
|
|
|
,
|
|
this function
|
|
<B>compare</B>
|
|
|
|
allows the module
|
|
<B>Bytes</B>
|
|
|
|
to be passed as
|
|
argument to the functors
|
|
<B>Set.Make</B>
|
|
|
|
and
|
|
<B>Map.Make</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val equal </I>
|
|
|
|
:
|
|
<B>t -> t -> bool</B>
|
|
|
|
<P>
|
|
The equality function for byte sequences.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Unsafe conversions (for advanced users)</H3>
|
|
|
|
<P>
|
|
This section describes unsafe, low-level conversion functions
|
|
between
|
|
<B>bytes</B>
|
|
|
|
and
|
|
<B>string</B>
|
|
|
|
. They do not copy the internal data;
|
|
used improperly, they can break the immutability invariant on
|
|
strings provided by the
|
|
<B>-safe-string</B>
|
|
|
|
option. They are available for
|
|
expert library authors, but for most purposes you should use the
|
|
always-correct
|
|
<B>Bytes.to_string</B>
|
|
|
|
and
|
|
<B>Bytes.of_string</B>
|
|
|
|
instead.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val unsafe_to_string </I>
|
|
|
|
:
|
|
<B>bytes -> string</B>
|
|
|
|
<P>
|
|
Unsafely convert a byte sequence into a string.
|
|
<P>
|
|
To reason about the use of
|
|
<B>unsafe_to_string</B>
|
|
|
|
, it is convenient to
|
|
consider an "ownership" discipline. A piece of code that
|
|
manipulates some data "owns" it; there are several disjoint ownership
|
|
modes, including:
|
|
<P>
|
|
-Unique ownership: the data may be accessed and mutated
|
|
<P>
|
|
-Shared ownership: the data has several owners, that may only
|
|
access it, not mutate it.
|
|
<P>
|
|
Unique ownership is linear: passing the data to another piece of
|
|
code means giving up ownership (we cannot write the
|
|
data again). A unique owner may decide to make the data shared
|
|
(giving up mutation rights on it), but shared data may not become
|
|
uniquely-owned again.
|
|
<P>
|
|
<P>
|
|
<B>unsafe_to_string s</B>
|
|
|
|
can only be used when the caller owns the byte
|
|
sequence
|
|
<B>s</B>
|
|
|
|
-- either uniquely or as shared immutable data. The
|
|
caller gives up ownership of
|
|
<B>s</B>
|
|
|
|
, and gains ownership of the
|
|
returned string.
|
|
<P>
|
|
There are two valid use-cases that respect this ownership
|
|
discipline:
|
|
<P>
|
|
1. Creating a string by initializing and mutating a byte sequence
|
|
that is never changed after initialization is performed.
|
|
<P>
|
|
<P>
|
|
<B>let string_init len f : string =</B>
|
|
|
|
|
|
|
|
<B>let s = Bytes.create len in</B>
|
|
|
|
<B>for i = 0 to len - 1 do Bytes.set s i (f i) done;</B>
|
|
|
|
<B>Bytes.unsafe_to_string s</B>
|
|
|
|
<B><P>
|
|
</B>
|
|
|
|
This function is safe because the byte sequence
|
|
<B>s</B>
|
|
|
|
will never be
|
|
accessed or mutated after
|
|
<B>unsafe_to_string</B>
|
|
|
|
is called. The
|
|
<B>string_init</B>
|
|
|
|
code gives up ownership of
|
|
<B>s</B>
|
|
|
|
, and returns the
|
|
ownership of the resulting string to its caller.
|
|
<P>
|
|
Note that it would be unsafe if
|
|
<B>s</B>
|
|
|
|
was passed as an additional
|
|
parameter to the function
|
|
<B>f</B>
|
|
|
|
as it could escape this way and be
|
|
mutated in the future --
|
|
<B>string_init</B>
|
|
|
|
would give up ownership of
|
|
<B>s</B>
|
|
|
|
to pass it to
|
|
<B>f</B>
|
|
|
|
, and could not call
|
|
<B>unsafe_to_string</B>
|
|
|
|
safely.
|
|
<P>
|
|
We have provided the
|
|
<B>String.init</B>
|
|
|
|
,
|
|
<B>String.map</B>
|
|
|
|
and
|
|
<B>String.mapi</B>
|
|
|
|
functions to cover most cases of building
|
|
new strings. You should prefer those over
|
|
<B>to_string</B>
|
|
|
|
or
|
|
<B>unsafe_to_string</B>
|
|
|
|
whenever applicable.
|
|
<P>
|
|
2. Temporarily giving ownership of a byte sequence to a function
|
|
that expects a uniquely owned string and returns ownership back, so
|
|
that we can mutate the sequence again after the call ended.
|
|
<P>
|
|
<P>
|
|
<B>let bytes_length (s : bytes) =</B>
|
|
|
|
|
|
|
|
<B>String.length (Bytes.unsafe_to_string s)</B>
|
|
|
|
<B><P>
|
|
</B>
|
|
|
|
In this use-case, we do not promise that
|
|
<B>s</B>
|
|
|
|
will never be mutated
|
|
after the call to
|
|
<B>bytes_length s</B>
|
|
|
|
. The
|
|
<B>String.length</B>
|
|
|
|
function
|
|
temporarily borrows unique ownership of the byte sequence
|
|
(and sees it as a
|
|
<B>string</B>
|
|
|
|
), but returns this ownership back to
|
|
the caller, which may assume that
|
|
<B>s</B>
|
|
|
|
is still a valid byte
|
|
sequence after the call. Note that this is only correct because we
|
|
know that
|
|
<B>String.length</B>
|
|
|
|
does not capture its argument -- it could
|
|
escape by a side-channel such as a memoization combinator.
|
|
<P>
|
|
The caller may not mutate
|
|
<B>s</B>
|
|
|
|
while the string is borrowed (it has
|
|
temporarily given up ownership). This affects concurrent programs,
|
|
but also higher-order functions: if
|
|
<B>String.length</B>
|
|
|
|
returned
|
|
a closure to be called later,
|
|
<B>s</B>
|
|
|
|
should not be mutated until this
|
|
closure is fully applied and returns ownership.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val unsafe_of_string </I>
|
|
|
|
:
|
|
<B>string -> bytes</B>
|
|
|
|
<P>
|
|
Unsafely convert a shared string to a byte sequence that should
|
|
not be mutated.
|
|
<P>
|
|
The same ownership discipline that makes
|
|
<B>unsafe_to_string</B>
|
|
|
|
correct applies to
|
|
<B>unsafe_of_string</B>
|
|
|
|
: you may use it if you were
|
|
the owner of the
|
|
<B>string</B>
|
|
|
|
value, and you will own the return
|
|
<B>bytes</B>
|
|
|
|
in the same mode.
|
|
<P>
|
|
In practice, unique ownership of string values is extremely
|
|
difficult to reason about correctly. You should always assume
|
|
strings are shared, never uniquely owned.
|
|
<P>
|
|
For example, string literals are implicitly shared by the
|
|
compiler, so you never uniquely own them.
|
|
<P>
|
|
<P>
|
|
<B>let incorrect = Bytes.unsafe_of_string hello</B>
|
|
|
|
|
|
|
|
<B>let s = Bytes.of_string hello</B>
|
|
|
|
<B><P>
|
|
</B>
|
|
|
|
The first declaration is incorrect, because the string literal
|
|
<B>hello</B>
|
|
|
|
could be shared by the compiler with other parts of the
|
|
program, and mutating
|
|
<B>incorrect</B>
|
|
|
|
is a bug. You must always use
|
|
the second version, which performs a copy and is thus correct.
|
|
<P>
|
|
Assuming unique ownership of strings that are not string
|
|
literals, but are (partly) built from string literals, is also
|
|
incorrect. For example, mutating
|
|
<B>unsafe_of_string (foo ^ s)</B>
|
|
|
|
could mutate the shared string
|
|
<B>foo</B>
|
|
|
|
-- assuming a rope-like
|
|
representation of strings. More generally, functions operating on
|
|
strings will assume shared ownership, they do not preserve unique
|
|
ownership. It is thus incorrect to assume unique ownership of the
|
|
result of
|
|
<B>unsafe_of_string</B>
|
|
|
|
.
|
|
<P>
|
|
The only case we have reasonable confidence is safe is if the
|
|
produced
|
|
<B>bytes</B>
|
|
|
|
is shared -- used as an immutable byte
|
|
sequence. This is possibly useful for incremental migration of
|
|
low-level programs that manipulate immutable sequences of bytes
|
|
(for example
|
|
<B>Marshal.from_bytes</B>
|
|
|
|
) and previously used the
|
|
<B>string</B>
|
|
|
|
type for this purpose.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Iterators</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val to_seq </I>
|
|
|
|
:
|
|
<B>t -> char Seq.t</B>
|
|
|
|
<P>
|
|
Iterate on the string, in increasing index order. Modifications of the
|
|
string during iteration will be reflected in the iterator.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.07
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val to_seqi </I>
|
|
|
|
:
|
|
<B>t -> (int * char) Seq.t</B>
|
|
|
|
<P>
|
|
Iterate on the string, in increasing order, yielding indices along chars
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.07
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val of_seq </I>
|
|
|
|
:
|
|
<B>char Seq.t -> t</B>
|
|
|
|
<P>
|
|
Create a string from the generator
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.07
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Binary encoding/decoding of integers</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
The functions in this section binary encode and decode integers to
|
|
and from byte sequences.
|
|
<P>
|
|
All following functions raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if the space
|
|
needed at index
|
|
<B>i</B>
|
|
|
|
to decode or encode the integer is not
|
|
available.
|
|
<P>
|
|
Little-endian (resp. big-endian) encoding means that least
|
|
(resp. most) significant bytes are stored first. Big-endian is
|
|
also known as network byte order. Native-endian encoding is
|
|
either little-endian or big-endian depending on
|
|
<B>Sys.big_endian</B>
|
|
|
|
.
|
|
<P>
|
|
32-bit and 64-bit integers are represented by the
|
|
<B>int32</B>
|
|
|
|
and
|
|
<B>int64</B>
|
|
|
|
types, which can be interpreted either as signed or
|
|
unsigned numbers.
|
|
<P>
|
|
8-bit and 16-bit integers are represented by the
|
|
<B>int</B>
|
|
|
|
type,
|
|
which has more bits than the binary encoding. These extra bits
|
|
are handled as follows:
|
|
<P>
|
|
-Functions that decode signed (resp. unsigned) 8-bit or 16-bit
|
|
integers represented by
|
|
<B>int</B>
|
|
|
|
values sign-extend
|
|
(resp. zero-extend) their result.
|
|
<P>
|
|
-Functions that encode 8-bit or 16-bit integers represented by
|
|
<B>int</B>
|
|
|
|
values truncate their input to their least significant
|
|
bytes.
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val get_uint8 </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_uint8 b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's unsigned 8-bit integer starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int8 </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int8 b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's signed 8-bit integer starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_uint16_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_uint16_ne b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's native-endian unsigned 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_uint16_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_uint16_be b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's big-endian unsigned 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_uint16_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_uint16_le b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's little-endian unsigned 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int16_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int16_ne b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's native-endian signed 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int16_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int16_be b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's big-endian signed 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int16_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int16_le b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's little-endian signed 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int32_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int32</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int32_ne b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's native-endian 32-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int32_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int32</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int32_be b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's big-endian 32-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int32_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int32</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int32_le b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's little-endian 32-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int64_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int64</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int64_ne b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's native-endian 64-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int64_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int64</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int64_be b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's big-endian 64-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_int64_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int64</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_int64_le b i</B>
|
|
|
|
is
|
|
<B>b</B>
|
|
|
|
's little-endian 64-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_uint8 </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_uint8 b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's unsigned 8-bit integer starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int8 </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int8 b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's signed 8-bit integer starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_uint16_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_uint16_ne b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's native-endian unsigned 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_uint16_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_uint16_be b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's big-endian unsigned 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_uint16_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_uint16_le b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's little-endian unsigned 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int16_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int16_ne b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's native-endian signed 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int16_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int16_be b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's big-endian signed 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int16_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int16_le b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's little-endian signed 16-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int32_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int32 -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int32_ne b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's native-endian 32-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int32_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int32 -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int32_be b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's big-endian 32-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int32_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int32 -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int32_le b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's little-endian 32-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int64_ne </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int64 -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int64_ne b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's native-endian 64-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int64_be </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int64 -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int64_be b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's big-endian 64-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_int64_le </I>
|
|
|
|
:
|
|
<B>bytes -> int -> int64 -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_int64_le b i v</B>
|
|
|
|
sets
|
|
<B>b</B>
|
|
|
|
's little-endian 64-bit integer
|
|
starting at byte index
|
|
<B>i</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAE">Unsafe conversions (for advanced users)</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Iterators</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">Binary encoding/decoding of integers</A><DD>
|
|
</DL>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:37 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|