JANA2
C++ framework for multi-threaded data processing
|
JMessage is an interface for data that can be streamed using JTransports. More...
#include <JMessage.h>
Public Member Functions | |
virtual char * | as_buffer ()=0 |
Expose the underlying buffer via a raw pointer. More... | |
virtual const char * | as_buffer () const =0 |
Expose the underlying buffer via a raw pointer. More... | |
virtual size_t | get_buffer_capacity () const =0 |
Determine the length of the buffer itself, a.k.a. More... | |
virtual size_t | get_buffer_size () const |
Determine the length of the buffer's contents, a.k.a. More... | |
virtual bool | is_end_of_stream () const =0 |
Determine whether this is the last message. More... | |
JMessage is an interface for data that can be streamed using JTransports.
The basic goal is to have an object wrapper around an old-fashioned char*
buffer which can be created automatically on either the stack or the heap. Most importantly, it encapsulates the mess arising from variable message lengths. A common pattern for solving this problem in C is to use flexible array members. Do NOT do this here, as this causes a variety of problems when it comes to type safety and memory safety, and it is not even part of any C++ standard. Instead, agree upon a max message size (which your transport needs anyway), and declare an array of that length. The array length (a.k.a. 'capacity') should be a compile-time constant, and the length of the data contained (a.k.a. 'size') should be tracked in a separate variable.
In addition to the pure virtual methods listed below, conforming implementations need a zero-argument constructor.
|
pure virtual |
Expose the underlying buffer via a raw pointer.
|
pure virtual |
Expose the underlying buffer via a raw pointer.
|
pure virtual |
Determine the length of the buffer itself, a.k.a.
the max number of bytes that can be written.
Referenced by get_buffer_size().
|
inlinevirtual |
Determine the length of the buffer's contents, a.k.a.
the number of bytes which ought to be read
References get_buffer_capacity().
|
pure virtual |
Determine whether this is the last message.
An end-of-stream message is assumed to also contain a meaningful payload. It is not empty like EOF. TODO: Figure out best way to handle empty end-of-stream as well as other control signals such as change-run.