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