Bug 1294 - New PeekU8 () and Read (Buffer::Iterator start, uint32_t size) methods in Buffer::Iterator
--- a/RELEASE_NOTES Fri Feb 21 11:50:18 2014 -0500
+++ b/RELEASE_NOTES Fri Feb 21 09:12:38 2014 +0100
@@ -31,6 +31,7 @@
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
--- a/src/network/model/buffer.h Fri Feb 21 11:50:18 2014 -0500
+++ b/src/network/model/buffer.h Fri Feb 21 09:12:38 2014 +0100
@@ -253,6 +253,13 @@
/**
* \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.
+ *
* Read data and advance the Iterator by the number of bytes
* read.
*/
@@ -334,12 +341,22 @@
* \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.
* \return checksum
@@ -816,7 +833,7 @@
}
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 @@
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 @@
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),