Page
Library
Module
Module type
Parameter
Class
Class type
Source
Bytes.SliceSourceByte slices.
A byte slice is a non-empty consecutive range of bytes in a Bytes.t value. The unique, distinguished, empty slice Slice.eod is used to indicate end of data.
The bytes in the range of a slice is made available to a third-party for a limited amount of time during which the slice is said to be valid for reading or writing (or both). Third parties are only allowed to access the bytes in the range and in the mode specified while it is valid.
The type for slice lengths. A positive integer.
default_length is io_buffer_size.
io_buffer_size is 65536 it should correspond to the value of OCaml's IO_BUFFER_SIZE. See here.
unix_io_buffer_size is 65536 it should correspond to the value of OCaml's UNIX_BUFFER_SIZE. See here.
check_length l is l if l > 0 and raises Invalid_argument otherwise.
The type for byte slices.
make b ~first ~length is a slice referencing the bytes of b in the range [first; first+length-1].
This function does not allow the creation of the empty Slice.eod which is a feature. It raises Invalid_argument if length is not positive, larger than the length of b or if first is out of bounds.
See also make_or_eod and of_bytes.
first s is the index, in bytes s, of the first byte of the byte range of s.
length s is the byte length of the byte range of s. This returns 0 only on eod.
copy ~tight s is a copy of s. If tight is true, the copy contains only the bytes in the range of s. If not the whole bytes s is copied.
eod is a slice to denote the end of data. It is the only slice with length d = 0. Its bytes are Bytes.empty.
equal s0 s1 is true iff the bytes in the slice ranges of s0 and s1 are equal.
compare s0 s1 sorts the bytes in the slice ranges of s0 and s1 in lexicographic order.
Warning. In these operations index specification are in slice space which starts at 0 at the slice's first byte.
sub s ~first ~length is the slice made of the consecutive bytes of the range b whose indices exist in the non-empty slice space range [first;first + length - 1]. Raises Invalid_argument if the interval is empty or out of bounds. See also sub_or_eod.
subrange ~first ~last s is the slice made of the consecutive bytes of the range of s whose indices exist in the non-empty slice space range [first;last].
first defaults to 0 and last to Slice.length s - 1. Note that both first and last can be any integer. If s is eod or if first > last the interval is empty and Invalid_argument is raised. See also subrange_or_eod and make.
of_bytes ~first ~last b is the slice made of the consecutive bytes of b whose indices exist in the non-empty range [first;last]. The bytes are not copied.
first defaults to 0 and last to Bytes.length s - 1. Note that both first and last can be any integer. If b is empty or if first > last the interval is empty and Invalid_argument is raised. See also of_bytes_or_eod.
val of_bigbytes :
?first:int ->
?last:int ->
(int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
tof_bigbytes is like of_bytes but copies data from a bigbytes value.
val of_bigbytes_or_eod :
?first:int ->
?last:int ->
(int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
tof_bytes_or_eod is like of_bytes_or_eod but copies data from a bigbytes value.
of_string s is of_bytes (Bytes.of_string s).
of_string_or_eod is of_bytes_or_eod (Bytes.of_string s).
to_bigbytes t copies the range of s to a new bigbytes value.
output_to_out_channel oc s outputs the byte range of s to oc. Warning. Make sure the channel is in binary mode. For example by default stdout is not.
pp formats a slice for inspection. This formats the range specification and at most the first four bytes of the buffer in hex.
pp' is like pp but prints raw bytes if hex is false (defaults to true) and prints at most head initial bytes (defaults to 4, use (-1) to format all the bytes).
val tracer :
?pp:(Format.formatter -> t -> unit) ->
?ppf:Format.formatter ->
id:string ->
t ->
unittracer ~pp ~ppf ~id is a function that formats slices on ppf (defaults to Format.err_formatter) with pp (defaults to pp) and the identifier id. Use with Reader.tap or Writer.tap.