![]() |
Project
|
#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 | |
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; } )
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::CheckHeaderFct = std::function<bool(const HeaderType&)> |
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::CheckTrailerFct = typename std::conditional< !std::is_void<U>::value, std::function<bool(const CheckTrailerFctArgumentT&)>, std::function<bool()> >::type |
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::CheckTrailerFctArgumentT = typename std::conditional< !std::is_void<TrailerType>::value, TrailerType, int>::type |
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::GetFrameSizeFct = std::function<size_t(const HeaderType&)> |
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::HeaderType = HeaderT |
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::InsertFct = std::function<bool(FrameInfo&)> |
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::PayloadType = unsigned char |
using o2::algorithm::ForwardParser< HeaderT, TrailerT >::TrailerType = TrailerT |
|
inline |
|
inline |
|
static |
|
static |
|
static |