File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,9 +82,20 @@ void LumpParser::feedByte(uint8_t byte) {
8282}
8383
8484void LumpParser::feedBytes (const uint8_t *data, int len) {
85+ // Add all bytes to the ring buffer first, then process once.
86+ // This ensures onDataFrameDispatched() fires only after the last
87+ // frame in the batch (count_ == 0), not after each individual frame.
8588 for (int i = 0 ; i < len; i++) {
86- feedByte (data[i]);
89+ if (count_ >= ringBufSize) {
90+ stats_.bufferOverflows ++;
91+ head_ = (head_ + 1 ) % ringBufSize;
92+ count_--;
93+ }
94+ uint16_t tail = (head_ + count_) % ringBufSize;
95+ buf_[tail] = data[i];
96+ count_++;
8797 }
98+ processBuffer ();
8899}
89100
90101auto LumpParser::stats () const -> const LumpParserStats & {
Original file line number Diff line number Diff line change @@ -376,7 +376,20 @@ class LumpParserT {
376376 }
377377
378378 void feedBytes (const uint8_t *data, int len) {
379- for (int i = 0 ; i < len; i++) feedByte (data[i]);
379+ // Pre-load all bytes into the ring buffer, then process once.
380+ // This ensures onDataFrameDispatched() fires only after the last
381+ // frame in the batch (count_ == 0), not after each individual frame.
382+ for (int i = 0 ; i < len; i++) {
383+ if (count_ >= RING_BUF_SIZE ) {
384+ stats_.bufferOverflows ++;
385+ head_ = (head_ + 1 ) % RING_BUF_SIZE ;
386+ count_--;
387+ }
388+ uint16_t tail = (head_ + count_) % RING_BUF_SIZE ;
389+ buf_[tail] = data[i];
390+ count_++;
391+ }
392+ processBuffer ();
380393 }
381394
382395 const LumpParserStats &stats () const { return stats_; }
You can’t perform that action at this time.
0 commit comments