Module MessageWrapper.Message
Contents
Instructions: Use this module in your project
In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:
Add the following to your project's
dependencies/CMakeLists.txt:DkSDKProject_DeclareAvailable(capnp CONSTRAINT "= 3.5.0" FINDLIBS capnp capnp.unix) DkSDKProject_MakeAvailable(capnp)Add the
Findlib::capnplibrary to any desired targets insrc/*/CMakeLists.txt:target_link_libraries(YourPackage_YourLibraryName # ... existing libraries, if any ... Findlib::capnp)Click your IDE's
Buildbutton
Not using DkSDK?
FIRST, do one or all of the following:
Run:
opam install capnp.3.5.0Edit your
dune-projectand add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (capnp (>= 3.5.0))))Then run:
dune build *.opam # if this fails, run: dune buildEdit your
<package>.opamfile and add:depends: [ # ... existing dependencies ... "capnp" {>= "3.5.0"} ]Then run:
opam install . --deps-only
FINALLY, add the capnp library to any desired (library)and/or (executable) targets in your **/dune files:
(library
(name YourLibrary)
; ... existing library options ...
(libraries
; ... existing libraries ...
capnp))
(executable
(name YourExecutable)
; ... existing executable options ...
(libraries
; ... existing libraries ...
capnp))include MessageSig.MESSAGE with type``'asegment_t:='a Segment.t
typestorage_t
storage_t is the type of the underlying storage associated with this
segment (e.g. "bytes").
typestorage_descr_t`` = ``{
segment :storage_t;
bytes_consumed : int;}
type``-'cap 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.
valcreate : ``int->MessageSig.rwt
create size allocates a new zero-filled single-segment message of at
least size bytes, raising an exception if storage cannot be allocated.
valrelease :'capt->unit
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.
valnum_segments :'capt->int
num_segments m obtains the number of segments associated with message
m.
valtotal_size :'capt->int
total_size m gets the total size of the message, in bytes, across all
segments.
valtotal_alloc_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.
get_segment m i gets zero-indexed segment i associated with message
m.
-
raises Invalid_argument
if the index is out of bounds.
valreadonly :'capt->MessageSig.rot
readonly m obtains a view of message m which is read-only qualified.
valof_storage :storage_tlist``->MessageSig.rwt
of_storage chunks constructs a read/write message which uses the list
of storage chunks as the underlying storage media for the message
segments.
valto_storage :'capt->storage_descr_tlist
to_storage m retrieves a list of the storage elements associated with
the message segments.
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_attachments :MessageSig.attachments->'capt->'capt
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.
valget_attachments :'capt->MessageSig.attachments
get_attachments m returns the handler previously set in
with_attachments, or No_attachments if no attachments were given.
