123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338(******************************************************************************
* capnp-ocaml
*
* Copyright (c) 2013-2014, Paul Pelzl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
******************************************************************************)typerotyperwmoduletypeSEGMENT=sig(** [storage_t] is the type of the underlying storage associated with
this segment (e.g. "bytes"). *)typestorage_t(** ['cap t] is the type of a message segment. The ['cap] annotation is
type [ro] for read-only segments, and type [rw] for read/write
segments. *)type-'capt(** [alloc size] allocates a new zero-filled message segment of at least
[size] bytes, raising an exception if storage cannot be allocated. *)valalloc:int->rwt(** [release s] immediately releases the storage associated with message
segment [s], potentially making the storage available for future
allocations. After releasing a storage segment, the behavior of
the accessor functions is undefined. *)valrelease:'capt->unit(** [length s] determines the length of this message segment. *)vallength:'capt->int(** [readonly s] obtains a view of segment [s] which is read-only qualified. *)valreadonly:'capt->rot(** [of_storage storage] constructs a read/write segment which uses the given
[storage] for the underlying storage media. *)valof_storage:storage_t->rwt(** [to_storage s] retrieves the underlying storage media associated with
segment [s]. *)valto_storage:'capt->storage_t(** [get_uintXX s ofs] reads an unsigned integer of the specified width,
starting at byte offset [ofs] within message segment [s]. *)valget_uint8:'capt->int->intvalget_uint16:'capt->int->intvalget_uint32:'capt->int->Uint32.tvalget_uint64:'capt->int->Uint64.t(** [get_intXX s ofs] reads a signed integer of the specified width,
starting at byte offset [ofs] within message segment [s]. *)valget_int8:'capt->int->intvalget_int16:'capt->int->intvalget_int32:'capt->int->Int32.tvalget_int64:'capt->int->Int64.t(** [set_uintXX s ofs val] writes the value of the width-restricted
unsigned integer [val] into read/write-qualified message segment [s],
starting at byte offset [ofs]. *)valset_uint8:rwt->int->int->unitvalset_uint16:rwt->int->int->unitvalset_uint32:rwt->int->Uint32.t->unitvalset_uint64:rwt->int->Uint64.t->unit(** [set_intXX s ofs val] writes the value of the width-restricted
signed integer [val] into read/write-qualified message segment [s],
starting at byte offset [ofs]. *)valset_int8:rwt->int->int->unitvalset_int16:rwt->int->int->unitvalset_int32:rwt->int->Int32.t->unitvalset_int64:rwt->int->Int64.t->unit(** [blit ~src ~src_pos ~dst ~dst_pos ~len] transfers [len] bytes
from position [dst_pos] in [dst] to position [src_pos] in [pos].
The blit operation shall work correctly even for the case of
overlapping buffers. *)valblit:src:('capt)->src_pos:int->dst:(rwt)->dst_pos:int->len:int->unit(** As [blit], but the destination is a [bytes] buffer. *)valblit_to_bytes:src:('capt)->src_pos:int->dst:Bytes.t->dst_pos:int->len:int->unit(** As [blit], but the source is a [string] buffer. *)valblit_from_string:src:string->src_pos:int->dst:(rwt)->dst_pos:int->len:int->unit(** [zero_out segment ~pos ~len] sets [len] bytes of the segment
to zero, beginning at byte offset [pos]. *)valzero_out:rwt->pos:int->len:int->unitend(** An RPC message can have an array of attached capabilities.
To avoid making the message layer depend on the RPC layer, we define this
as an open type, so that an RPC system can use whatever system it likes for
this. *)typeattachments=..(** This is the default attachment handler. *)typeattachments+=No_attachmentsmoduletypeMESSAGE=sig(** [storage_t] is the type of the underlying storage associated with
this segment (e.g. "bytes"). *)typestorage_ttypestorage_descr_t={(** Storage for one of the message segments *)segment:storage_t;(** Number of bytes actually consumed in this segment *)bytes_consumed:int;}type-'capsegment_t(** ['cap t] is the type of a message. The ['cap] annotation is type [ro]
for read-only segments, and type [rw] for read/write segments. *)type-'capt(** [create size] allocates a new zero-filled single-segment message of at
least [size] bytes, raising an exception if storage cannot be allocated. *)valcreate:int->rwt(** [release m] immediately releases the storage for all segments of message
[m], potentially making the storage available for future allocations.
After releasing a storage segment, the behavior of the accessor functions
is undefined. *)valrelease:'capt->unit(** [num_segments m] obtains the number of segments associated with message [m]. *)valnum_segments:'capt->int(** [total_size m] gets the total size of the message, in bytes, across all
segments. *)valtotal_size:'capt->int(** [total_alloc_size m] gets total size of the underlying storage for the
message, in bytes, across all segments. (This is at least as large
as the value returned by [total_size]. *)valtotal_alloc_size:'capt->int(** [get_segment m i] gets zero-indexed segment [i] associated with message [m].
@raise Invalid_argument if the index is out of bounds. *)valget_segment:'capt->int->'capsegment_t(** [readonly m] obtains a view of message [m] which is read-only qualified. *)valreadonly:'capt->rot(** [of_storage chunks] constructs a read/write message which uses the list of
storage [chunks] as the underlying storage media for the message segments. *)valof_storage:storage_tlist->rwt(** [to_storage m] retrieves a list of the storage elements associated with
the message segments. *)valto_storage:'capt->storage_descr_tlist(** [with_message m ~f] first evaluates [f m], then invokes [release m], then
returns the result of the application of [f]. If [f m] raises an exception,
the exception will be propagated after a call to [release]. *)valwith_message:'capt->f:('capt->'a)->'a(** [with_attachments attachments m] is a message sharing the same storage as [m],
but with the given attachments. If [m] is mutable, it should not be used after
calling this. Effectively, [attachments] is a constructor argument, but it isn't
known until slightly after the message is constructed. *)valwith_attachments:attachments->'capt->'capt(** [get_attachments m] returns the handler previously set in [with_attachments],
or [No_attachments] if no attachments were given. *)valget_attachments:'capt->attachmentsendmoduletypeSLICE=sigtype-'capsegment_ttype-'capmessage_t(** Type [t] represents a contiguous range of bytes associated with a single
segment of a message. *)type'capt={msg:'capmessage_t;(** Identifies the message of interest *)segment:'capsegment_t;(** Segment within message housing these bytes *)segment_id:int;(** Index of the segment *)start:int;(** Starting byte of the slice *)len:int;(** Length of the slice, in bytes *)}(** [alloc m size] reserves [size] bytes of space within message [m]. This
may result in extending the message with an additional segment; if
storage cannot be allocated for a new segment, an exception is raised.
Note that the allocated slices always begin on an eight-byte boundary. *)valalloc:rwmessage_t->int->rwt(** [alloc_in_segment m seg_id size] attempts to reserve [size] bytes of space
within segment [seg_id] of message [m]. Allocation will fail if the
segment is full. *)valalloc_in_segment:rwmessage_t->int->int->rwtoption(** [get_segment slice] gets the message segment associated with the [slice]. *)valget_segment:'capt->'capsegment_t(** [get_end slice] computes [slice.start] + [slice.len]. *)valget_end:'capt->int(** [readonly s] obtains a view of slice [s] which is read-only qualified. *)valreadonly:'capt->rot(** [get_uintXX s ofs] reads an unsigned integer of the specified width,
starting at byte offset [ofs] within the [slice]. *)valget_uint8:'capt->int->intvalget_uint16:'capt->int->intvalget_uint32:'capt->int->Uint32.tvalget_uint64:'capt->int->Uint64.t(** [get_intXX s ofs] reads a signed integer of the specified width,
starting at byte offset [ofs] within the [slice]. *)valget_int8:'capt->int->intvalget_int16:'capt->int->intvalget_int32:'capt->int->Int32.tvalget_int64:'capt->int->Int64.t(** [set_uintXX s ofs val] writes the value of the width-restricted
unsigned integer [val] into the read/write-qualified [slice],
starting at byte offset [ofs]. *)valset_uint8:rwt->int->int->unitvalset_uint16:rwt->int->int->unitvalset_uint32:rwt->int->Uint32.t->unitvalset_uint64:rwt->int->Uint64.t->unit(** [set_intXX s ofs val] writes the value of the width-restricted
signed integer [val] into the read/write-qualified [slice],
starting at byte offset [ofs]. *)valset_int8:rwt->int->int->unitvalset_int16:rwt->int->int->unitvalset_int32:rwt->int->Int32.t->unitvalset_int64:rwt->int->Int64.t->unit(** [blit ~src ~src_pos ~dst ~dst_pos ~len] copies [len] bytes from the
source slice (beginning at [src_pos]) to the destination slice
(beginning at [dst_pos]). *)valblit:src:('capt)->src_pos:int->dst:(rwt)->dst_pos:int->len:int->unit(** As [blit], but the destination is a [bytes] buffer. *)valblit_to_bytes:src:('capt)->src_pos:int->dst:Bytes.t->dst_pos:int->len:int->unit(** As [blit], but the source is a [string] buffer. *)valblit_from_string:src:string->src_pos:int->dst:(rwt)->dst_pos:int->len:int->unit(** [zero_out ~pos ~len slice] sets [len] bytes of the [slice]
to zero, beginning at byte offset [pos]. *)valzero_out:rwt->pos:int->len:int->unitendmoduletypeS=sigmoduleSegment:sigincludeSEGMENTendmoduleMessage:sigincludeMESSAGEwithtype'asegment_t:='aSegment.tendmoduleSlice:sigincludeSLICEwithtype'asegment_t:='aSegment.tandtype'amessage_t:='aMessage.tendmoduleStructStorage:sig(* Note: ['a] is marked covariant here just because it makes casting easier in some places. *)type('cap,+'a)t=private{data:'capSlice.t;pointers:'capSlice.t;}valreadonly:('cap,'a)t->(ro,'a)tvalwith_attachments:attachments->('cap,'a)t->('cap,'a)tvalget_attachments:('cap,'a)t->attachmentsvalv:data:'capSlice.t->pointers:'capSlice.t->('cap,'a)tvalcast:('cap,'a)t->('cap,'b)ttype'areader_t=(ro,'a)toptiontype'abuilder_t=(rw,'a)tvalreader_of_builder:'abuilder_t->'areader_tvalmessage_of_builder:_builder_t->rwMessage.tvalcast_reader:'areader_t->'breader_tendmoduleListStorage:sigtype'capt={storage:'capSlice.t;storage_type:ListStorageType.t;num_elements:int;}valreadonly:'capt->rotendmoduleObject:sigtype('cap,'a)t=|None|Listof'capListStorage.t|Structof('cap,'a)StructStorage.t|CapabilityofUint32.tendend