type buffer = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.tType of buffer. A t is composed of an underlying buffer.
create len is a fresh read-and-write t of size len. with an offset of 0, filled with zero bytes.
create_unsafe len is a fresh read-and-write t of size len with an offset of 0.
Note that the returned cstruct will contain arbitrary data, likely including the contents of previously-deallocated cstructs.
Beware!
Forgetting to replace this data could cause your application to leak sensitive information.
of_string ~off ~len s is a fresh read-and-write t of s sliced on off (default is 0) and of len (default is String.length s) length.
of_bytes ~off ~len x is a fresh read-and-write t of x sliced on off (default is 0) and of len (default is Bytes.length x) length.
to_bigarray t converts t into a buffer Bigarray, using the Bigarray slicing to allocate a fresh proxy Bigarray that preserves sharing of the underlying buffer.
In other words:
let t = Cstruct_cap.create 10 in
let b = Cstruct_cap.to_bigarray t in
Bigarray.Array1.set b 0 '\x42' ;
assert (Cstruct_cap.get_char t 0 = '\x42')equal a b is true iff a and b correspond to the same sequence of bytes (it uses memcmp internally). Both need at least read capability rd.
check_alignment t alignment is true if the first byte stored within t is at a memory address where address mod alignment = 0, false otherwise. The mod used has the C/OCaml semantic (which differs from Python). Typical uses are to check a buffer is aligned to a page or disk sector boundary. t needs at least read capability rd.
- raises Invalid_argument
 if
alignmentis not a positive integer.
get_char t off returns the character contained in t at offset off. t needs at least read capability rd.
- raises Invalid_argument
 if the offset exceeds
tlength (which can differ from underlying buffer length).
get_uint8 t off returns the byte contained in t at offset off. t needs at least read capability rd.
- raises Invalid_argument
 if the offset exceeds
tlength (which can differ from underlying buffer length).
set_char t off c sets the character contained in t at offset off to character c. t needs at least write capability wr.
- raises Invalid_argument
 if the offset exceeds
tlength (which can differ from underlying buffer length).
set_uint8 t off x sets the byte contained in t at offset off to byte x. t needs at least write capability wr.
- raises Invalid_argument
 if the offset exceeds
tlength (which can differ from underlying buffer length).
to_string ~off ~len t is the string representation of the segment of t starting at off (default is 0) of size len (default is length t). t needs at least read-capability rd.
- raises Invalid_argument
 if
offandlendoes not designate a valid segment oft.
to_bytes ~off ~len t is the bytes representation of the segment of t starting at off (default is 0) of size len (default is length t). t needs at least read-capability rd.
- raises Invalid_argument
 if
offandlendo not designate a valid segment oft.
blit src ~src_off dst ~dst_off ~len copies len characters from src, starting at index src_off, to dst, starting at index dst_off. It works correctly even if src and dst have the same underlying buffer, and the src and dst intervals overlap. This function uses memmove internally.
src needs at least read-capability rd. dst needs at least write-capability wr. Both don't share capabilities.
- raises Invalid_argument
 if
src_offandlendo not designate a valid segment ofsrc, or ifdst_offandlendo not designate a valid segment ofdst.
blit_from_string src ~src_off dst ~dst_off ~len copies len characters from src, starting at index src_off, to dst, starting at index dst_off. This function uses memcpy internally.
dst needs at least write-capability wr.
- raises Invalid_argument
 if
src_offandlendo not designate a valid sub-string ofsrc, or ifdst_offandlendo not designate a valid segment ofdst.
blit_from_bytes src ~src_off dst ~dst_off ~len copies len characters from src, starting at index src_off, to dst, starting at index dst_off. This uses memcpy internally.
dst needs at least write-capability wr.
- raises Invalid_argument
 if
src_offandlendo not designate a valid sub-sequence ofsrc, or ifdst_offandlendo no designate a valid segment ofdst.
blit_to_bytes src ~src_off dst ~dst_off ~len copies len characters from src, starting at index src_off, to sequences dst, starting at index dst_off. blit_to_bytes uses memcpy internally.
src needs at least read-capability rd.
- raises Invalid_argument
 if
src_offandlendo not designate a valid segment ofsrc, or ifdst_offandlendo not designate a valid sub-seuqnce ofdst.
memset t x sets all bytes of t to x land 0xff. t needs at least write-capability wr.
split ~start t len is a tuple containing ts extracted from t at offset start (default is 0) of length len as first element, and the rest of t as second element.
- raises Invalid_argument
 if
sartexceeds thetlength, or if there is a bounds violation oftvialen + start.
val pp : Stdlib.Format.formatter -> 'a rd t -> unitmodule BE : sig ... endmodule LE : sig ... endfillv ~src ~dst copies from src to dst until src is exhausted or dst is full. It returns the number of bytes copied and the remaining data from src, if any. This is useful if you want to bufferize data into fixed-sized chunks. Each t of src need at least read-capability rd. dst needs at least write-capability wr. Each t of src and dst don't share capabilities.
iter lenf of_cstruct t is an iterator over t that returns elements of size lenf t and type of_cstruct t. t needs at least read-capability rd and iter keeps capabilities of t on of_cstruct.
val fold : ('acc -> 'x -> 'acc) -> 'x iter -> 'acc -> 'accfold f iter acc is (f iterN accN ... (f iter acc)...).