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

#include <Parser.h>

Classes

struct  FrameInfo
 

Public Types

using HeaderType = HeaderT
 
using TrailerType = TrailerT
 
using PayloadType = unsigned char
 
using CheckHeaderFct = std::function< bool(const HeaderType &)>
 
using CheckTrailerFctArgumentT = typename std::conditional< !std::is_void< TrailerType >::value, TrailerType, int >::type
 
template<typename U >
using CheckTrailerFct = typename std::conditional< !std::is_void< U >::value, std::function< bool(const CheckTrailerFctArgumentT &)>, std::function< bool()> >::type
 
using GetFrameSizeFct = std::function< size_t(const HeaderType &)>
 
using InsertFct = std::function< bool(FrameInfo &)>
 

Public Member Functions

template<typename InputType >
int parse (const InputType *buffer, size_t bufferSize, CheckHeaderFct checkHeader, CheckTrailerFct< TrailerType > checkTrailer, GetFrameSizeFct getFrameSize, InsertFct insert)
 
template<typename InputType , typename U = TrailerType>
std::enable_if< std::is_void< U >::value, int >::type parse (const InputType *buffer, size_t bufferSize, CheckHeaderFct checkHeader, 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 = void>
class o2::algorithm::ForwardParser< HeaderT, TrailerT >

Parser for a sequence of frames with header, trailer and variable payload. The size is expected to be part of the header.

Trailer type can be void, which is also the default template parameter. That allows to define a frame consisting of only header and data.

Usage:

  using SomeParser = ForwardParser<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::HeaderType& h) {
                 // get the size of the frame including payload
                 // and header and trailer size, e.g. payload size
                 // from a header member
                 return h.payloadSize + SomeParser::totalOffset;
               },
               [&frames] (typename SomeParser::FrameInfo& info) {
                 frames.emplace_back(info);
                 return true;
               }
               )

  // a reduced version without trailer check callback
  using SomeParser = ForwardParser<SomeHeaderType>;
  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::HeaderType& h) {
                 // get the size of the frame including payload
                 // and header and trailer size, e.g. payload size
                 // from a header member
                 return h.payloadSize + SomeParser::totalOffset;
               },
               [&frames] (typename SomeParser::FrameInfo& info) {
                 frames.emplace_back(info);
                 return true;
               }
               )

Definition at line 99 of file Parser.h.

Member Typedef Documentation

◆ CheckHeaderFct

template<typename HeaderT , typename TrailerT = void>
using o2::algorithm::ForwardParser< 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 126 of file Parser.h.

◆ CheckTrailerFct

template<typename HeaderT , typename TrailerT = void>
template<typename U >
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::CheckTrailerFct = typename std::conditional< !std::is_void<U>::value, std::function<bool(const CheckTrailerFctArgumentT&)>, std::function<bool()> >::type

alias for callback checking the trailer, takes reference to trailer object if TrailerType is a valid type, no argument otherwise

Definition at line 137 of file Parser.h.

◆ CheckTrailerFctArgumentT

template<typename HeaderT , typename TrailerT = void>
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::CheckTrailerFctArgumentT = typename std::conditional< !std::is_void<TrailerType>::value, TrailerType, int>::type

alias for the argument type to be used in the CheckTrailer function have to forward to a valid type in case of void TrailerType in order to allow passing by reference

Definition at line 131 of file Parser.h.

◆ GetFrameSizeFct

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

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

Definition at line 144 of file Parser.h.

◆ HeaderType

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

Definition at line 102 of file Parser.h.

◆ InsertFct

template<typename HeaderT , typename TrailerT = void>
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::InsertFct = std::function<bool(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 148 of file Parser.h.

◆ PayloadType

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

Definition at line 104 of file Parser.h.

◆ TrailerType

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

Definition at line 103 of file Parser.h.

Member Function Documentation

◆ parse() [1/2]

template<typename HeaderT , typename TrailerT = void>
template<typename InputType >
int o2::algorithm::ForwardParser< HeaderT, TrailerT >::parse ( const InputType buffer,
size_t  bufferSize,
CheckHeaderFct  checkHeader,
CheckTrailerFct< TrailerType 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 154 of file Parser.h.

◆ parse() [2/2]

template<typename HeaderT , typename TrailerT = void>
template<typename InputType , typename U = TrailerType>
std::enable_if< std::is_void< U >::value, int >::type o2::algorithm::ForwardParser< HeaderT, TrailerT >::parse ( const InputType buffer,
size_t  bufferSize,
CheckHeaderFct  checkHeader,
GetFrameSizeFct  getFrameSize,
InsertFct  insert 
)
inline

Parse buffer of size bufferSize, specialization skipping the trailer check, e.g. when its type is void, or when the integrity of the trailer is not relevant. Requires callbacks to check header, frame size, and insert callback to handle a FrameInfo object.

Definition at line 232 of file Parser.h.

Member Data Documentation

◆ headOffset

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

the length offset due to header

Definition at line 118 of file Parser.h.

◆ tailOffset

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

the length offset due to trailer

Definition at line 120 of file Parser.h.

◆ totalOffset

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

total length offset due to header and trailer

Definition at line 122 of file Parser.h.


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