@@ -110,8 +110,8 @@ class ConcreteRawParser
110110 return *reinterpret_cast <header_type const *>(mPosition );
111111 }
112112
113- // / Get length of payload at current position
114- size_t length () const
113+ // / Get size of payload at current position
114+ size_t size () const
115115 {
116116 if (mPosition == mRawBuffer + mSize ) {
117117 return 0 ;
@@ -124,17 +124,36 @@ class ConcreteRawParser
124124 // / Get pointer to payload data at current position
125125 buffer_type const * data () const
126126 {
127- size_t len = length ();
128- if (len == 0 ) {
127+ size_t size = this -> size ();
128+ if (size == 0 ) {
129129 return nullptr ;
130130 }
131131 header_type const & h = header ();
132- if (mPosition + len + h.headerSize > mRawBuffer + mSize ) {
132+ if (mPosition + size + h.headerSize > mRawBuffer + mSize ) {
133133 throw std::runtime_error (" not enough data at position " + std::to_string (mPosition - mRawBuffer ));
134134 }
135135 return mPosition + h.headerSize ;
136136 }
137137
138+ // / Get pointer to raw buffer at current position
139+ buffer_type const * raw () const
140+ {
141+ if (mPosition < mRawBuffer + mSize ) {
142+ return mPosition ;
143+ }
144+ return nullptr ;
145+ }
146+
147+ // / Get offset of payload in the raw buffer at current position
148+ size_t offset () const
149+ {
150+ if (mPosition < mRawBuffer + mSize ) {
151+ header_type const & h = header ();
152+ return h.headerSize ;
153+ }
154+ return 0 ;
155+ }
156+
138157 // / Parse the complete buffer
139158 // / For each page, the processor function is called with the payload buffer and size,
140159 // / processor has signature
@@ -145,7 +164,7 @@ class ConcreteRawParser
145164 reset ();
146165 // auto deleter = [](buffer_type*) {};
147166 do {
148- processor (data (), length ());
167+ processor (data (), size ());
149168 // processor(std::unique_ptr<buffer_type, decltype(deleter)>(data(), deleter), size());
150169 } while (next ());
151170 }
@@ -299,15 +318,15 @@ U const* get_if(T& instances)
299318// /
300319// / // option 1: parse method
301320// / RawParser parser(buffer, size);
302- // / auto processor = [&count](auto data, size_t length ) {
303- // / std::cout << "Processing block of length " << length << std::endl;
321+ // / auto processor = [&count](auto data, size_t size ) {
322+ // / std::cout << "Processing block of size " << size << std::endl;
304323// / };
305324// / parser.parse(processor);
306325// /
307326// / // option 2: iterator
308327// / RawParser parser(buffer, size);
309328// / for (auto it = parser.begin(), end = parser.end(); it != end; ++it, ++count) {
310- // / std::cout << "Iterating block of length " << it.length () << std::endl;
329+ // / std::cout << "Iterating block of size " << it.size () << std::endl;
311330// / auto dataptr = it.data();
312331// / }
313332// /
@@ -366,7 +385,7 @@ class RawParser
366385 // / - increment (there is no decrement, its not a bidirectional parser)
367386 // / - dereference operator returns @a RawDataHeaderInfo as common header
368387 // / - member function data() returns pointer to payload at current position
369- // / - member function length () return size of payload at current position
388+ // / - member function size () return size of payload at current position
370389 template <typename T, typename ParentType>
371390 class Iterator : public IteratorBase <T>
372391 {
@@ -417,16 +436,28 @@ class RawParser
417436 return not operator ==(rh);
418437 }
419438
439+ // / get pointer to raw block at current position, rdh starts here
440+ buffer_type const * raw () const
441+ {
442+ return std::visit ([](auto & parser) { return parser.raw (); }, mParser );
443+ }
444+
420445 // / get pointer to payload at current position
421446 buffer_type const * data () const
422447 {
423448 return std::visit ([](auto & parser) { return parser.data (); }, mParser );
424449 }
425450
426- // / get length of payload at current position
427- size_t length () const
451+ // / offset of payload at current position
452+ size_t offset () const
453+ {
454+ return std::visit ([](auto & parser) { return parser.offset (); }, mParser );
455+ }
456+
457+ // / get size of payload at current position
458+ size_t size () const
428459 {
429- return std::visit ([](auto & parser) { return parser.length (); }, mParser );
460+ return std::visit ([](auto & parser) { return parser.size (); }, mParser );
430461 }
431462
432463 // / get header as specific type
0 commit comments