Project
Loading...
Searching...
No Matches
o2::algorithm::ReverseParser< HeaderT, TrailerT > Class Template Reference

#include <Parser.h>

Classes

struct  FrameInfo
 of header, data, and trailer More...
 

Public Types

using HeaderType = HeaderT
 
using TrailerType = TrailerT
 
using PayloadType = unsigned char
 
using CheckHeaderFct = std::function< bool(const HeaderType &)>
 
using CheckTrailerFct = std::function< bool(const TrailerType &)>
 alias for callback checking the trailer
 
using GetFrameSizeFct = std::function< size_t(const TrailerType &)>
 
using InsertFct = std::function< bool(const FrameInfo &)>
 

Public Member Functions

template<typename InputType >
int parse (const InputType *buffer, size_t bufferSize, CheckHeaderFct checkHeader, CheckTrailerFct checkTrailer, GetFrameSizeFct getFrameSize, InsertFct insert)
 

Static Public Attributes

static const size_t headOffset = typesize<HeaderType>::size
 the length offset due to header
 
static const size_t tailOffset = typesize<TrailerType>::size
 the length offset due to trailer
 
static const size_t totalOffset = headOffset + tailOffset
 total length offset due to header and trailer
 

Detailed Description

template<typename HeaderT, typename TrailerT>
class o2::algorithm::ReverseParser< HeaderT, TrailerT >

Parser for a sequence of frames with header, trailer and variable payload. The size is expected to be part of the trailer, the parsing is thus in reverse direction. Also the insert callback is called with the entries starting form the end of the buffer. TODO: an easy extension can be to reverse the order of the inserts, meaning that the entries are read from the beginning.

Usage:

  using SomeParser = ReverseParser<SomeHeaderType, SomeTrailerType>;
  SomeParser parser;
  std::vector<typename SomeParser::FrameInfo> frames;
  parser.parse(ptr, size,
               [] (const typename SomeParser::HeaderType& h) {
                 // check the header
                 return true;
               },
               [] (const typename SomeParser::TrailerType& t) {
                 // check the trailer
                 return true;
               },
               [] (const typename SomeParser::TrailerType& t) {
                 // get the size of the frame including payload
                 // and header and trailer size, e.g. payload size
                 // from a trailer member
                 return t.payloadSize + SomeParser::totalOffset;
               },
               [&frames] (typename SomeParser::FrameInfo& info) {
                 frames.emplace_back(info);
                 return true;
               }
               )

Definition at line 296 of file Parser.h.

Member Typedef Documentation

◆ CheckHeaderFct

template<typename HeaderT , typename TrailerT >
using o2::algorithm::ReverseParser< HeaderT, TrailerT >::CheckHeaderFct = std::function<bool(const HeaderType&)>

alias for callback checking the header, return true if the object is a valid header

Definition at line 321 of file Parser.h.

◆ CheckTrailerFct

template<typename HeaderT , typename TrailerT >
using o2::algorithm::ReverseParser< HeaderT, TrailerT >::CheckTrailerFct = std::function<bool(const TrailerType&)>

alias for callback checking the trailer

Definition at line 323 of file Parser.h.

◆ GetFrameSizeFct

template<typename HeaderT , typename TrailerT >
using o2::algorithm::ReverseParser< HeaderT, TrailerT >::GetFrameSizeFct = std::function<size_t(const TrailerType&)>

alias for callback to get the complete frame size including header, trailer and the data

Definition at line 326 of file Parser.h.

◆ HeaderType

template<typename HeaderT , typename TrailerT >
using o2::algorithm::ReverseParser< HeaderT, TrailerT >::HeaderType = HeaderT

Definition at line 299 of file Parser.h.

◆ InsertFct

template<typename HeaderT , typename TrailerT >
using o2::algorithm::ReverseParser< HeaderT, TrailerT >::InsertFct = std::function<bool(const FrameInfo&)>

function callback to insert/handle one frame into, sequentially called for all frames if the whole block has a valid format

Definition at line 329 of file Parser.h.

◆ PayloadType

template<typename HeaderT , typename TrailerT >
using o2::algorithm::ReverseParser< HeaderT, TrailerT >::PayloadType = unsigned char

Definition at line 301 of file Parser.h.

◆ TrailerType

template<typename HeaderT , typename TrailerT >
using o2::algorithm::ReverseParser< HeaderT, TrailerT >::TrailerType = TrailerT

Definition at line 300 of file Parser.h.

Member Function Documentation

◆ parse()

template<typename HeaderT , typename TrailerT >
template<typename InputType >
int o2::algorithm::ReverseParser< HeaderT, TrailerT >::parse ( const InputType buffer,
size_t  bufferSize,
CheckHeaderFct  checkHeader,
CheckTrailerFct  checkTrailer,
GetFrameSizeFct  getFrameSize,
InsertFct  insert 
)
inline

Parse buffer of size bufferSize, requires callbacks to check header trailer, the frame size, and insert callback to handle a FrameInfo object.

Definition at line 335 of file Parser.h.

Member Data Documentation

◆ headOffset

template<typename HeaderT , typename TrailerT >
const size_t o2::algorithm::ReverseParser< HeaderT, TrailerT >::headOffset = typesize<HeaderType>::size
static

the length offset due to header

Definition at line 313 of file Parser.h.

◆ tailOffset

template<typename HeaderT , typename TrailerT >
const size_t o2::algorithm::ReverseParser< HeaderT, TrailerT >::tailOffset = typesize<TrailerType>::size
static

the length offset due to trailer

Definition at line 315 of file Parser.h.

◆ totalOffset

template<typename HeaderT , typename TrailerT >
const size_t o2::algorithm::ReverseParser< HeaderT, TrailerT >::totalOffset = headOffset + tailOffset
static

total length offset due to header and trailer

Definition at line 317 of file Parser.h.


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