From 7daf507a803a1011e2230b092f5009a54dc05599 Mon Sep 17 00:00:00 2001 From: Alexander Afanasyev Date: Fri, 21 Feb 2014 09:12:38 +0100 Subject: [PATCH] Bug 1294 - New PeekU8 () and Read (Buffer::Iterator start, uint32_t size) methods in Buffer::Iterator --- RELEASE_NOTES | 1 + src/network/model/buffer.h | 42 +++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 96c5a7692..dcb8fe156 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -31,6 +31,7 @@ New user-visible features Bugs fixed ---------- +- Bug 1294 - New PeekU8 () and Read (Buffer::Iterator start, uint32_t size) methods in Buffer::Iterator - Bug 1653 - Extension of CommandLine interface: restored operator << (CommandLine) - Bug 1739 - The endpoint is not deallocated for UDP sockets - Bug 1786 - os << int64x64_t prints un-normalized fractional values diff --git a/src/network/model/buffer.h b/src/network/model/buffer.h index 632ed7fb9..487ba7b3f 100644 --- a/src/network/model/buffer.h +++ b/src/network/model/buffer.h @@ -250,6 +250,13 @@ public: */ void Write (Iterator start, Iterator end); + /** + * \return the byte read in the buffer. + * + * Read data, but do not advance the Iterator read. + */ + inline uint8_t PeekU8 (void); + /** * \return the byte read in the buffer. * @@ -334,11 +341,21 @@ public: * \param size number of bytes to copy * * Copy size bytes of data from the internal buffer to the - * input buffer and avance the Iterator by the number of + * input buffer and advance the Iterator by the number of * bytes read. */ void Read (uint8_t *buffer, uint32_t size); + /** + * \param start start iterator of the buffer to copy data into + * \param size number of bytes to copy + * + * Copy size bytes of data from the internal buffer to the input buffer via + * the provided iterator and advance the Iterator by the number of bytes + * read. + */ + inline void Read (Iterator start, uint32_t size); + /** * \brief Calculate the checksum. * \param size size of the buffer. @@ -816,7 +833,7 @@ Buffer::Iterator::ReadNtohU32 (void) } uint8_t -Buffer::Iterator::ReadU8 (void) +Buffer::Iterator::PeekU8 (void) { NS_ASSERT_MSG (m_current >= m_dataStart && m_current <= m_dataEnd, @@ -825,22 +842,27 @@ Buffer::Iterator::ReadU8 (void) if (m_current < m_zeroStart) { uint8_t data = m_data[m_current]; - m_current++; return data; } else if (m_current < m_zeroEnd) { - m_current++; return 0; } else { uint8_t data = m_data[m_current - (m_zeroEnd-m_zeroStart)]; - m_current++; return data; } } +uint8_t +Buffer::Iterator::ReadU8 (void) +{ + uint8_t ret = PeekU8 (); + m_current ++; + return ret; +} + uint16_t Buffer::Iterator::ReadU16 (void) { @@ -853,6 +875,16 @@ Buffer::Iterator::ReadU16 (void) return data; } +void +Buffer::Iterator::Read (Buffer::Iterator start, uint32_t size) +{ + Buffer::Iterator end = *this; + end.Next (size); + + start.Write (*this, end); +} + + Buffer::Buffer (Buffer const&o) : m_data (o.m_data), m_maxZeroAreaStart (o.m_zeroAreaStart),