Module Lwt_bytes
Byte arrays
type t= (char, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.tType of array of bytes.
val create : int -> tCreates a new byte array of the given size.
val length : t -> intReturns the length of the given byte array.
Access
val get : t -> int -> charget buffer offsetreturns the byte at offsetoffsetinbuffer.
val set : t -> int -> char -> unitget buffer offset valuechanges the value of the byte at offsetoffsetinbuffertovalue.
Conversions
val of_bytes : bytes -> tof_bytes bufreturns a newly allocated byte array with the same contents asbuf.
val of_string : string -> tof_string bufreturns a newly allocated byte array with the same contents asbuf.
val to_bytes : t -> bytesto_bytes bufreturns newly allocated bytes with the same contents asbuf.
val to_string : t -> stringto_string bufreturns a newly allocated string with the same contents asbuf.
Copying
val blit : t -> int -> t -> int -> int -> unitblit buf1 ofs1 buf2 ofs2 lencopieslenbytes frombuf1starting at offsetofs1tobuf2starting at offsetofs2.
val blit_from_bytes : bytes -> int -> t -> int -> int -> unitSame as
blitbut the first buffer is a string instead of a byte array.
val blit_to_bytes : t -> int -> bytes -> int -> int -> unitSame as
blitbut the second buffer is a string instead of a byte array.
val unsafe_blit_from_bytes : bytes -> int -> t -> int -> int -> unitSame as
Lwt_bytes.blit_from_bytesbut without bounds checking.
val unsafe_blit_to_bytes : t -> int -> bytes -> int -> int -> unitSame as
Lwt_bytes.blit_to_bytesbut without bounds checking.
val proxy : t -> int -> int -> tproxy buffer offset lengthcreates a ``proxy''. The returned byte array share the data ofbufferbut with different bounds.
Filling
val fill : t -> int -> int -> char -> unitfill buffer offset length valueputsvaluein alllengthbytes ofbufferstarting at offsetoffset.
IOs
val read : Lwt_unix.file_descr -> t -> int -> int -> int Lwt.tval write : Lwt_unix.file_descr -> t -> int -> int -> int Lwt.tval recv : Lwt_unix.file_descr -> t -> int -> int -> Unix.msg_flag list -> int Lwt.tNot implemented on Windows.
val send : Lwt_unix.file_descr -> t -> int -> int -> Unix.msg_flag list -> int Lwt.tNot implemented on Windows.
val recvfrom : Lwt_unix.file_descr -> t -> int -> int -> Unix.msg_flag list -> (int * Unix.sockaddr) Lwt.tNot implemented on Windows.
val sendto : Lwt_unix.file_descr -> t -> int -> int -> Unix.msg_flag list -> Unix.sockaddr -> int Lwt.tNot implemented on Windows.
type io_vector={iov_buffer : t;iov_offset : int;iov_length : int;}
val io_vector : buffer:t -> offset:int -> length:int -> io_vectorval recv_msg : socket:Lwt_unix.file_descr -> io_vectors:io_vector list -> (int * Unix.file_descr list) Lwt.tNot implemented on Windows.
- deprecated
val send_msg : socket:Lwt_unix.file_descr -> io_vectors:io_vector list -> fds:Unix.file_descr list -> int Lwt.tNot implemented on Windows.
- deprecated
Memory mapped files
val map_file : fd:Unix.file_descr -> ?pos:int64 -> shared:bool -> ?size:int -> unit -> tmap_file ~fd ?pos ~shared ?size ()maps the file descriptorfdto an array of bytes.
val mapped : t -> boolmapped bufferreturnstrueiffbufferis a memory mapped file.
type advice=|MADV_NORMAL|MADV_RANDOM|MADV_SEQUENTIAL|MADV_WILLNEED|MADV_DONTNEED|MADV_MERGEABLE|MADV_UNMERGEABLE|MADV_HUGEPAGE|MADV_NOHUGEPAGEType of advise that can be sent to the kernel by the program. See the manual madvise(2) for a description of each.
val madvise : t -> int -> int -> advice -> unitmadvise buffer pos len adviceadvises the kernel how the program will use the memory mapped file betweenposandpos + len.This call is not available on windows.
val mincore : t -> int -> bool array -> unitmincore buffer offset statestests whether the given pages are in the system memory (the RAM). Theoffsetargument must be a multiple ofpage_size.statesis used to store the result; each cases istrueif the corresponding page is in RAM andfalseotherwise.This call is not available on windows and cygwin.