Module IO.ReadContext
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 "= " 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.nullEdit your
dune-projectand add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (capnp (>= ))))Then run:
dune build *.opam # if this fails, run: dune buildEdit your
<package>.opamfile and add:depends: [ # ... existing dependencies ... "capnp" {>= ""} ]Then run:
opam install . --deps-only
FINALLY, add the capnp.unix library to any desired (library)and/or (executable) targets in your **/dune files:
(library
(name YourLibrary)
; ... existing library options ...
(libraries
; ... existing libraries ...
capnp.unix))
(executable
(name YourExecutable)
; ... existing executable options ...
(libraries
; ... existing libraries ...
capnp.unix))type``'a t
valcreate : ``read:``('a->``buf:Stdlib.Bytes.t->``pos:int->``len:int->int)``->``compression:Capnp.Codecs.compression_t->'a->'at
create ~read ~compression descr creates a new context for reading data
from the specified descriptor using the specified compression method.
The semantics of the read function shall mimic that of Unix.read,
attempting to read into a substring of the buf and returning the
number of bytes actually read. A read of length 0 indicates end-of-file.
valdequeue_message :'at->Capnp.Message.rwCapnp.Message.BytesMessage.Message.toption
dequeue_message context attempts to remove a complete message from the
incoming queue of the read context. No data will be read from the
underlying descriptor.
-
returns
None if there is insufficient data stored in the read context to decode a complete message
-
raises Unsupported_message_frame
if the frame header describes a segment count or segment size that is too large for the implementation
valbytes_available :'at->int
bytes_available context obtains the number of bytes already read which
are currently stored in the read context.
valread :'at->int
read context attempts to read some data from the underlying
descriptor, storing it in the read context.
-
returns
the number of bytes actually read
valread_message :'at->Capnp.Message.rwCapnp.Message.BytesMessage.Message.toption
read_message context attempts to remove a complete message from the
incoming queue of the read context. read may be invoked repeatedly
to provide enough buffered data to decode a complete message.
-
returns
None if end-of-file was reached before a complete message could be read
-
raises Unsupported_message_frame
if the frame header describes a segment count or segment size that is too large for the implementation
