@@ -71,6 +71,9 @@ class raw_eater
7171 // save all data, i.e. physical values of measured entities as 64bit double
7272 std::vector<double > datmes_;
7373
74+ // error message queue
75+ std::string error_queue_;
76+
7477 // check format validity
7578 bool valid_ = true ;
7679
@@ -105,6 +108,9 @@ class raw_eater
105108 segments_.clear ();
106109 datmes_.clear ();
107110
111+ // reset error queue
112+ error_queue_ = std::string (" " );
113+
108114 // do setup and conversion
109115 // setup_and_conversion(showlog);
110116 }
@@ -152,6 +158,11 @@ class raw_eater
152158 // check result
153159 if ( segments_.size () == 0 || datmes_.size () == 0 ) valid_ = false ;
154160 }
161+ else
162+ {
163+ // throw error with collected error messages
164+ throw std::runtime_error (error_queue_);
165+ }
155166 }
156167
157168 // display buffer/data properties
@@ -167,6 +178,8 @@ class raw_eater
167178 std::cout<<" \n " ;
168179 for ( auto el: markers_ )
169180 {
181+ assert ( el.second .size () > 0 && " please don't define any empty markers" );
182+
170183 std::cout<<el.first <<" " ;
171184 for ( unsigned char c: el.second ) std::cout<<std::hex<<int (c);
172185 std::cout<<" \n " ;
@@ -185,10 +198,8 @@ class raw_eater
185198
186199 for (std::pair<std::string,std::vector<unsigned char >> mrk : markers_ )
187200 {
188- assert ( mrk.second .size () > 0 && " please don't define any empty markers" );
189-
190201 // find marker's byte sequence in buffer
191- for ( unsigned long int idx = 0 ; idx < rawdata_.size (); idx++ )
202+ for ( unsigned long int idx = 0 ; idx < ( rawdata_.size () - mrk. second . size () ); idx++ )
192203 {
193204 // for every byte in buffer, check, if the three subsequent bytes
194205 // correspond to required predefined marker
@@ -203,26 +214,51 @@ class raw_eater
203214 {
204215 // array of data associated to marker
205216 std::vector<unsigned char > markseq;
217+ int seqidx = 0 ;
206218
219+ // read any marker but the data marker
207220 if ( mrk.first != " datas marker" )
208221 {
209- // collect bytes until we find semicolon ";", i.e. 0x3b
210- int seqidx = 0 ;
222+ // collect bytes until we find a semicolon ";", i.e. 0x3b (or until buffer is depleted)
211223 while ( rawdata_[idx+seqidx] != 0x3b )
212224 {
213225 markseq.push_back (rawdata_[idx+seqidx]);
214226 seqidx++;
227+
228+ // if buffer is depleted before we find the proper termination of
229+ // the markers, the data seems to be corrupted!!
230+ if ( idx+seqidx == rawdata_.size ()-1 )
231+ {
232+ std::string errmess = mrk.first + std::string (" is corrupted" );
233+ // throw std::runtime_error(errmess);
234+ error_queue_ += errmess + std::string (" - " );
235+ break ;
236+ }
215237 }
216238 }
239+ // data marker is supposed to be located at the very end of the buffer
240+ // but still be terminated by a semicolon (but may contain any number
241+ // of semicolons in between)
217242 else
218243 {
219- // marker 'datas' is the data marker and is supposed to be the last
220- // and should extend until end of file
221- for ( unsigned long int didx = idx; didx < rawdata_.size ()-1 ; didx++ )
244+ // collect data sequence (ignoring final semicolon)
245+ while ( idx+seqidx < rawdata_.size ()-1 )
222246 {
223- markseq.push_back (rawdata_[didx]);
247+ markseq.push_back (rawdata_[idx+seqidx]);
248+ seqidx++;
249+ }
250+
251+ // check for terminating semicolon
252+ if ( rawdata_.back () != 0x3b )
253+ {
254+ std::string errmess = mrk.first + std::string (" is corrupted" );
255+ error_queue_ += errmess + std::string (" - " );
224256 }
257+ }
225258
259+ // find length of data sequence
260+ if ( mrk.first == " datas marker" )
261+ {
226262 // obtain length of data segment
227263 datsize_ = markseq.size ();
228264 }
@@ -240,21 +276,25 @@ class raw_eater
240276 if ( datasec_[mrk.first ].size () == 0 )
241277 {
242278 std::string errmess = mrk.first + std::string (" not found in buffer" );
243- // std::cerr<<errmess;
244- try {
245- throw std::runtime_error (errmess);
246- } catch ( const std::exception& e ) {
247- throw ;
248- // std::cout<<e.what()<<"\n";
249- }
279+ // // std::cerr<<errmess;
280+ // try {
281+ // throw std::runtime_error(errmess);
282+ // } catch( const std::exception& e ) {
283+ // throw;
284+ // //std::cout<<e.what()<<"\n";
285+ // }
286+ error_queue_ += errmess + std::string (" - " );
287+
288+ // if any of the required (essential) markers are missing => invalid!
289+ valid_ = false ;
250290 }
251291 totalmarksize += datasec_[mrk.first ].size ();
252292 }
253293 // std::cout<<"totalmarksize "<<totalmarksize<<"\n";
254294 // std::cout<<"\n";
255295
256296 // check validity of format
257- valid_ = ( totalmarksize < 100 ) ? false : true ;
297+ // valid_ = ( totalmarksize < 100 ) ? false : true;
258298 }
259299
260300 // display content of found markers
0 commit comments