Module Codecs.FramedStream
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
t
The type of streams containing framed messages.
val
empty :
compression_t
->
t
empty compression
returns a new stream for decoding data stored with
the given compression
method. The stream initially contains no data.
val
of_string : ``compression:
compression_t
->
``string
->
t
of_string ~compression buf
returns a new stream which is filled with
the contents of the given buffer, where the buffer contains data
compressed with the specified compression
method.
val
add_fragment :
t
->
``string
->
unit
add_fragment stream fragment
adds a new fragment to the stream for
decoding. Fragments are processed in FIFO order.
val
bytes_available :
t
->
int
bytes_available stream
obtains the number of bytes in the stream which
have not yet been fully decoded.
val
is_empty :
t
->
bool
is_empty stream
determines whether or not the stream contains any data
which has not yet been fully decoded.
val
get_next_frame :
t
->
``(
Message.rw
Message.BytesMessage.Message.t
,
FramingError.t
)``
Result.result
get_next_frame
attempts to decode the next frame from the stream. A
successful decode removes the data from the stream and returns the frame
data in the form of a BytesMessage.