Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MessageSegmenter Class Referenceabstract

Abstract base class for segmenting a byte stream typed input into meaningful packet sized chunks. More...

#include <DirectHub.hxx>

Inheritance diagram for MessageSegmenter:
Destructable DirectHubGcSegmenter DirectHubTrivialSegmenter

Public Member Functions

virtual ssize_t segment_message (const void *data, size_t size)=0
 Makes a segmenting decision given more input data.
 
virtual void clear ()=0
 Resets internal state machine.
 

Detailed Description

Abstract base class for segmenting a byte stream typed input into meaningful packet sized chunks.

Implementations have to be stateful and are instantiated per specific input port. Implementations have to be thread-compatible.

Definition at line 126 of file DirectHub.hxx.

Member Function Documentation

◆ clear()

virtual void MessageSegmenter::clear ( )
pure virtual

Resets internal state machine.

The next call to segment_message() assumes no previous data present.

Implemented in DirectHubGcSegmenter, and DirectHubTrivialSegmenter.

◆ segment_message()

virtual ssize_t MessageSegmenter::segment_message ( const void *  data,
size_t  size 
)
pure virtual

Makes a segmenting decision given more input data.

This function will be called by the input routine repeatedly with the additional payload (non-overlapping) until the function returns a non-zero response.

That response tells how many bytes long the last packet was, which must be <= the sum of the size arguments passed in. Thereafter the read flow will call clear() and call segment_message() again with the remaining partial buffer.

Parameters
databeginning of the buffer pointing to the next unsegmented data array.
sizehow many bytes of data are available at this address. Must be >0.
Returns
0 if no complete packet was yet seen; positive value N if the packet that starts in the first segment_message call is N bytes long. Negative return are reserved (shall not be returned at this point).

Implemented in DirectHubGcSegmenter, and DirectHubTrivialSegmenter.


The documentation for this class was generated from the following file: