package mstruct

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module MstructSource

Mutable byte windows on top of Cstruct bigarrays

Sourcetype t

Type for mutable windows on top of bigarrays, with bounds automatically updated when values are read/write in the buffer.

Sourceval create : int -> t

Create a new buffer.

Sourceval of_string : ?allocator:(int -> Cstruct.t) -> string -> t

Create a buffer from a string.

Sourceval to_string : t -> string

Create a string from a buffer.

Sourceval length : t -> int

Get the buffer length.

Sourceval offset : t -> int

Get the buffer offset.

Sourceval sub : t -> int -> int -> t

Return a sub-window of the given buffer window.

Sourceval clone : t -> t

Clone the window buffer (the actual contents is still shared).

Sourceval shift : t -> int -> unit

Shift the buffer window. Negative offsets are supported.

Sourceval index : t -> char -> int option

Return the offset corresponding to the first occurence of the character in the given string.

Errors

Sourceexception Parse_error of string

Parse error

Sourceval parse_error_buf : t -> ('a, unit, string, 'b) format4 -> 'a

Print an error message, the buffer contents and raise a exception

Sourceval parse_error : ('a, unit, string, 'b) format4 -> 'a

Print an error message and raise an exception

Sourceval hexdump : t -> unit

Same as Cstruct.hexdump.

Sourceval hexdump_to_buffer : Buffer.t -> t -> unit

Same as Cstruct.hexdump_to_buffer

Sourceval debug : t -> string

Same as Cstruct.debug.

Basic IO operations

Get/set big-endian integers of various sizes.

Sourceval get_char : t -> char

get_char buf return the character stored in buf.

Sourceval get_uint8 : t -> int

get_uint8 buf is the 8 bit unsigned integer stored in buf.

Sourceval get_be_uint16 : t -> int

get_uint16 buf is the 16 bit long big-endian unsigned integer stored in buf.

Sourceval get_be_uint32 : t -> int32

get_uint32 buf is the 32 bit long big-endian unsigned integer stored in buf.

Sourceval get_be_uint64 : t -> int64

get_uint64 buf is the 64 bit long big-endian unsigned integer stored in buf.

Sourceval get_string : t -> int -> string

get_string buf len is the string of size len stored in buf.

Sourceval pick_string : t -> int -> string option

pick_string buf len looks for the string of size len in the buffer, without consuming it. Return None if the buffer is bigger than len.

Sourceval get_delim : t -> char -> (t -> 'a) -> 'a option

get_delim buf c fn builds a subwindow of buf by looking at the first occurence of the character c. Once the window is built, apply fn on the resulting buffer. Return None if c does not appear in the current buffer.

Sourceval get_string_delim : t -> char -> string option

get_string_delim buf c returns the string appearing between the start of the buffer buf and ending at the first occurence of the character c. Return None if c does not appear in buf.

Setters

Sourceval set_char : t -> char -> unit

set_char buf off c write the character c in buf at offset off.

Sourceval set_uint8 : t -> int -> unit

set_uint8 buf write the 8 bit long integer stored in buf.

Sourceval set_be_uint16 : t -> int -> unit

set_uint16 buf i writes the 16 bit long big-endian unsigned integer i in buf.

Sourceval set_be_uint32 : t -> int32 -> unit

set_uint32 buf i writes the 32 bit long big-endian unsigned integer i in buf.

Sourceval set_be_uint64 : t -> int64 -> unit

set_uint64 buf i writes the 64 bit long big-endian unsigned integer i in buf.

Sourceval set_string : t -> string -> unit

set_string buf str write the string str into buf.

Little endian

Sourceval get_le_uint16 : t -> int

get_uint16 buf is the 16 bit long little-endian unsigned integer stored in buf.

Sourceval get_le_uint32 : t -> int32

get_uint32 buf is the 32 bit long little-endian unsigned integer stored in buf.

Sourceval get_le_uint64 : t -> int64

get_uint64 buf is the 64 bit long little-endian unsigned integer stored in buf.

Sourceval set_le_uint16 : t -> int -> unit

set_uint16 buf i writes the 16 bit long little-endian unsigned integer i in buf.

Sourceval set_le_uint32 : t -> int32 -> unit

set_uint32 buf i writes the 32 bit long little-endian unsigned integer i in buf.

Sourceval set_le_uint64 : t -> int64 -> unit

set_uint64 buf i writes the 64 bit long little-endian unsigned integer i in buf.

Bigarrays

Sourceval of_bigarray : ?off:int -> ?len:int -> Cstruct.buffer -> t

of_bigarray ~off ~len b is the mstruct contained in b starting at off, of length len.

Sourceval to_bigarray : t -> Cstruct.buffer

Accessor. Return the underlying bigarray.

Cstructs

Sourceval of_cstruct : Cstruct.t -> t

Create mutable cstruct.

Sourceval to_cstruct : t -> Cstruct.t

Create an immutable cstruct.

Sourceval with_mstruct : Cstruct.t -> (t -> unit) -> unit

with_mstruct c f apply f to of_cstruct c.