From 7b321fba3e8ae69aae96ba994cb616a9d4e9bf8a Mon Sep 17 00:00:00 2001 From: Alexander Afanasyev Date: Wed, 18 Apr 2012 12:18:42 -0700 Subject: [PATCH] network: Adding Read (Buffer::Iterator start, uint32_t size) and PeakU8 methods to ns3::Buffer::Iterator class --- src/network/model/buffer.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/network/model/buffer.h b/src/network/model/buffer.h index 95b5f4eb4..b5f8337fe 100644 --- a/src/network/model/buffer.h +++ b/src/network/model/buffer.h @@ -248,6 +248,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. * @@ -332,11 +339,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. @@ -813,6 +830,14 @@ Buffer::Iterator::ReadNtohU32 (void) return retval; } +uint8_t +Buffer::Iterator::PeekU8 (void) +{ + uint8_t ret = ReadU8 (); + Prev (); + return ret; +} + uint8_t Buffer::Iterator::ReadU8 (void) { @@ -851,6 +876,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),