package extunix

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

big endian functions

  • author Goswin von Brederlow

Conversion functions from host to big endian byte order and back

Conversion of 16bit integers

val uint16_from_host : int -> int

uint16_from_host u16 converts an unsigned 16bit integer from host to big endian byte order

val int16_from_host : int -> int

int16_from_host i16 converts a signed 16bit integer from host to big endian byte order

val uint16_to_host : int -> int

uint16_to_host u16 converts an unsigned 16bit integer from big endian to host byte order

val int16_to_host : int -> int

int16_to_host i16 converts a signed 16bit integer from big endian to host byte order

Conversion of 31bit integeres On 64bit platforms this actualy converts 32bit integers without the need to allocate a new int32. On 32bit platforms it produces garbage. For use on 64bit platforms only!

val uint31_from_host : int -> int

uint31_from_host u31 converts an unsigned 31bit integer from host to big endian byte order

val int31_from_host : int -> int

int31_from_host i31 converts a signed 31bit integer from host to big endian byte order

val uint31_to_host : int -> int

uint31_to_host u31 converts an unsigned 31bit integer from big endian to host byte order

val int31_to_host : int -> int

int31_to_host i31 converts a signed 31bit integer from big endian to host byte order

Conversion of 32bit integers

val int32_from_host : int32 -> int32

int32_from_host int32 converts a 32bit integer from host to big endian byte order

val int32_to_host : int32 -> int32

int32_to_host int32 converts a 32bit integer from big endian to host byte order

Conversion of 64bit integers

val int64_from_host : int64 -> int64

int64_from_host int64 converts a 64bit integer from host to big endian byte order

val int64_to_host : int64 -> int64

int64_to_host int64 converts a 64bit integer from big endian to host byte order

val unsafe_get_uint8 : string -> int -> int

unsafe_get_X str off extract integer of type X from string str starting at offset off. Unsigned types are 0 extended and signed types are sign extended to fill the ocaml type. Bounds checking is not performed. Use with caution and only when the program logic guarantees that the access is within bounds.

Note: The 31bit functions extract a 32bit integer and return it as ocaml int. On 32bit platforms this can overflow as ocaml integers are 31bit signed there. No error is reported if this occurs. Use with care. Note: The same applies to 63bit functions.

val unsafe_get_int8 : string -> int -> int
val unsafe_get_uint16 : string -> int -> int
val unsafe_get_int16 : string -> int -> int
val unsafe_get_uint31 : string -> int -> int
val unsafe_get_int31 : string -> int -> int
val unsafe_get_int32 : string -> int -> int32
val unsafe_get_uint63 : string -> int -> int
val unsafe_get_int63 : string -> int -> int
val unsafe_get_int64 : string -> int -> int64
val get_uint8 : string -> int -> int

get_X str off same as unsafe_get_X but with bounds checking.

val get_int8 : string -> int -> int
val get_uint16 : string -> int -> int
val get_int16 : string -> int -> int
val get_uint31 : string -> int -> int
val get_int31 : string -> int -> int
val get_int32 : string -> int -> int32
val get_uint63 : string -> int -> int
val get_int63 : string -> int -> int
val get_int64 : string -> int -> int64
val unsafe_set_uint8 : Bytes.t -> int -> int -> unit

unsafe_set_X buf off v stores the integer v as type X in the buffer buf starting at offset off. Bounds checking is not performed. Use with caution and only when the program logic guarantees that the access is within bounds.

Note: The 31bit functions store an ocaml int as 32bit integer. On 32bit platforms ocaml integers are 31bit signed and will be sign extended to 32bit first. Use with care. Note: The same applies to 63bit functions.

val unsafe_set_int8 : Bytes.t -> int -> int -> unit
val unsafe_set_uint16 : Bytes.t -> int -> int -> unit
val unsafe_set_int16 : Bytes.t -> int -> int -> unit
val unsafe_set_uint31 : Bytes.t -> int -> int -> unit
val unsafe_set_int31 : Bytes.t -> int -> int -> unit
val unsafe_set_int32 : Bytes.t -> int -> int32 -> unit
val unsafe_set_uint63 : Bytes.t -> int -> int -> unit
val unsafe_set_int63 : Bytes.t -> int -> int -> unit
val unsafe_set_int64 : Bytes.t -> int -> int64 -> unit
val set_uint8 : Bytes.t -> int -> int -> unit

set_X buf off v same as unsafe_set_X but with bounds checking.

val set_int8 : Bytes.t -> int -> int -> unit
val set_uint16 : Bytes.t -> int -> int -> unit
val set_int16 : Bytes.t -> int -> int -> unit
val set_uint31 : Bytes.t -> int -> int -> unit
val set_int31 : Bytes.t -> int -> int -> unit
val set_int32 : Bytes.t -> int -> int32 -> unit
val set_uint63 : Bytes.t -> int -> int -> unit
val set_int63 : Bytes.t -> int -> int -> unit
val set_int64 : Bytes.t -> int -> int64 -> unit
OCaml

Innovation. Community. Security.