Module type MessageSig.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::capnp
library to any desired targets insrc/*/CMakeLists.txt
:target_link_libraries(YourPackage_YourLibraryName # ... existing libraries, if any ... Findlib::capnp)
Click your IDE's
Build
button
Not using DkSDK?
FIRST, do one or all of the following:
Run:
opam install capnp.3.5.0
Edit your
dune-project
and add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (capnp (>= 3.5.0))))
Then run:
dune build *.opam # if this fails, run: dune build
Edit your
<package>.opam
file 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))
type
storage_t
storage_t
is the type of the underlying storage associated with this
segment (e.g. "bytes").
type
storage_descr_t`` = ``{
segment :
storage_t
;
bytes_consumed : int;
}
type
``-'cap segment_t
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.
create size
allocates a new zero-filled single-segment message of at
least size
bytes, raising an exception if storage cannot be allocated.
val
release :
'cap
t
->
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.
val
num_segments :
'cap
t
->
int
num_segments m
obtains the number of segments associated with message
m
.
val
total_size :
'cap
t
->
int
total_size m
gets the total size of the message, in bytes, across all
segments.
val
total_alloc_size :
'cap
t
->
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.
of_storage chunks
constructs a read/write message which uses the list
of storage chunks
as the underlying storage media for the message
segments.
val
to_storage :
'cap
t
->
storage_descr_t
list
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
.
val
with_attachments :
attachments
->
'cap
t
->
'cap
t
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.
val
get_attachments :
'cap
t
->
attachments
get_attachments m
returns the handler previously set in
with_attachments
, or No_attachments
if no attachments were given.