Module Unsafe_common

module Unsafe_common: sig .. end
Functions common to unsafe binary protocol conversion.

NOTE: these functions are not supposed to be called by the casual user. They are required by automatically generated code, or if a developer really needs to get down and dirty for performance reasons.


type sptr 
Type of start pointers
type eptr 
Type of end pointers
type sptr_ptr 
Type of pointers to start pointers
val get_sptr : Common.buf -> pos:Common.pos -> sptr
get_sptr buf ~pos
Returns a start pointer given buffer buf and start position pos.
val get_eptr : Common.buf -> pos:Common.pos -> eptr
get_eptr buf ~pos
Returns an end pointer given buffer buf and end position pos.
val shift_sptr : sptr -> int -> sptr
shift_sptr sptr n
Returns a start pointer by shifting sptr by n characters.
val get_eptr_from_sptr_ptr : sptr_ptr -> pos:Common.pos -> eptr
get_eptr_from_sptr_ptr sptr_ptr ~pos
Returns an end pointer by obtaining the position pos after location sptr_ptr.
val get_buf_pos : start:sptr -> cur:sptr -> Common.pos
get_buf_pos ~start ~cur
Returns a buffer position as difference between start pointers start and cur.
val get_safe_buf_pos : Common.buf ->
start:sptr -> cur:sptr -> Common.pos
get_safe_buf_pos buf ~start ~cur
Returns a buffer position as difference between start pointers start and cur. buf is ignored, but prevents the buffer from being reclaimed by the GC, which it needs to until this function gets called.
val alloc_sptr_ptr : Common.buf -> pos:Common.pos -> sptr_ptr
alloc_sptr_ptr buf ~pos allocate a pointer to a start pointer. NOTE: do not forget to deallocate it, otherwise there will be a space leak! NOTE: The "noalloc" attribute is correct, because it indicates there is no OCaml allocation. alloc_sptr_ptr only does C allocation.
val dealloc_sptr_ptr : Common.buf -> sptr_ptr -> Common.pos
dealloc_sptr_ptr buf sptr_ptr deallocate a pointer to a start pointer and return its position. NOTE: do not do this more than once, otherwise the program may crash!
val get_sptr_ptr : sptr_ptr -> Common.buf -> Common.pos
get_sptr_ptr sptr_ptr buf
Returns the position in buffer buf denoted by the pointer stored in sptr_ptr.
val set_sptr_ptr : sptr_ptr -> Common.buf -> pos:Common.pos -> unit
set_sptr_ptr sptr_ptr buf ~pos sets the pointer in sptr_ptr to the location denoted by position pos in buffer buf.
val get_sptr_ptr_sptr : sptr_ptr -> sptr
get_sptr_ptr_sptr sptr_ptr
Returns the pointer in sptr_ptr.
val set_sptr_ptr_sptr : sptr_ptr -> sptr -> unit
set_sptr_ptr_sptr sptr_ptr sptr sets the pointer in sptr_ptr to sptr.
val get_ptr_string : sptr -> eptr -> string
get_ptr_string sptr_ptr eptr
Returns the string in the range from start pointer sptr to end pointer eptr.
val get_read_init : Common.buf ->
pos_ref:Common.pos Pervasives.ref ->
sptr_ptr * eptr
get_read_init buf ~pos_ref
Returns the sptr_ptr denoting the start and the eptr denoting the end of buffer buf. NOTE: do not forget to deallocate the sptr_ptr!