From 3d53c9911473e4564247e344bfa92b259dd570cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20L=C3=BCke?= Date: Wed, 22 Nov 2023 20:18:41 +0100 Subject: [PATCH] cleanup mvlc_nng_replay --- src/mvlc_nng_replay.cc | 84 ------------------------------------------ 1 file changed, 84 deletions(-) diff --git a/src/mvlc_nng_replay.cc b/src/mvlc_nng_replay.cc index 73fa73e..6d08d4e 100644 --- a/src/mvlc_nng_replay.cc +++ b/src/mvlc_nng_replay.cc @@ -9,90 +9,6 @@ using namespace mesytec; using namespace mesytec::mvlc; -// Follows the framing structure inside the buffer until an incomplete frame -// which doesn't fit into the buffer is detected. The incomplete data is moved -// over to the tempBuffer so that the readBuffer ends with a complete frame. -// -// The input buffer must start with a frame header (skip_count will be called -// with the first word of the input buffer on the first iteration). -// -// The SkipCountFunc must return the number of words to skip to get to the next -// frame header or 0 if there is not enough data left in the input iterator to -// determine the frames size. -// Signature of SkipCountFunc: u32 skip_count(const basic_string_view &view); -// Returns the number of trailing bytes copied from msgBuf into tmpBuf. -template -inline size_t fixup_buffer( - const u8 *msgBuf, size_t msgUsed, - std::vector &tmpBuf, - SkipCountFunc skip_count) -{ - auto view = basic_string_view(msgBuf, msgUsed); - - while (!view.empty()) - { - if (view.size() >= sizeof(u32)) - { - u32 wordsToSkip = skip_count(view); - - //cout << "wordsToSkip=" << wordsToSkip << ", view.size()=" << view.size() << ", in words:" << view.size() / sizeof(u32)); - - if (wordsToSkip == 0 || wordsToSkip > view.size() / sizeof(u32)) - { - tmpBuf.reserve(tmpBuf.size() + view.size()); - std::copy(std::begin(view), std::end(view), std::back_inserter(tmpBuf)); - return view.size(); - } - - // Skip over the SystemEvent frame or the ETH packet data. - view.remove_prefix(wordsToSkip * sizeof(u32)); - } - } - - return 0u; -} - -inline size_t fixup_buffer_mvlc_usb(const u8 *buf, size_t bufUsed, std::vector &tmpBuf) -{ - auto skip_func = [] (const basic_string_view &view) -> u32 - { - if (view.size() < sizeof(u32)) - return 0u; - - u32 header = *reinterpret_cast(view.data()); - return 1u + extract_frame_info(header).len; - }; - - return fixup_buffer(buf, bufUsed, tmpBuf, skip_func); -} - -inline size_t fixup_buffer_mvlc_eth(const u8 *buf, size_t bufUsed, std::vector &tmpBuf) -{ - auto skip_func = [](const basic_string_view &view) -> u32 - { - if (view.size() < sizeof(u32)) - return 0u; - - // Either a SystemEvent header or the first of the two ETH packet headers - u32 header = *reinterpret_cast(view.data()); - - if (get_frame_type(header) == frame_headers::SystemEvent) - return 1u + extract_frame_info(header).len; - - if (view.size() >= 2 * sizeof(u32)) - { - u32 header1 = *reinterpret_cast(view.data() + sizeof(u32)); - eth::PayloadHeaderInfo ethHdrs{ header, header1 }; - return eth::HeaderWords + ethHdrs.dataWordCount(); - } - - // Not enough data to get the 2nd ETH header word. - return 0u; - }; - - return fixup_buffer(buf, bufUsed, tmpBuf, skip_func); -} - int allocate_reserve_message(nng_msg **msg, size_t reserve = 0) { assert(msg);