1 #ifndef WIBBLE_SYS_NETBUFFER_H 2 #define WIBBLE_SYS_NETBUFFER_H 48 :
Buffer(buf, size, own), cursor(0) {}
50 :
Buffer(buf, size), cursor(0) {}
71 const void*
data(
size_t ofs = 0)
const throw () {
return static_cast<const char*
>(
Buffer::data()) + cursor + ofs; }
74 void*
data(
size_t ofs = 0) throw () {
return static_cast<char*
>(
Buffer::data()) + cursor + ofs; }
84 bool fits(
size_t ofs = 0)
const throw ()
86 return cursor + ofs +
sizeof(T) <
size();
93 const T*
cast(
size_t ofs = 0)
const throw (
wibble::exception::Consistency)
95 if (cursor + ofs +
sizeof(T) >=
size())
97 return static_cast<const T*
>(
data(ofs));
154 if (cursor + t >=
size())
Variable-size, reference-counted memory buffer.
Definition: buffer.h:33
const NetBuffer after(size_t ofs) const
Return another NetBuffer starting ofs bytes from the beginning of this one.
Definition: netbuffer.h:111
void * data(size_t ofs=0)
Return a pointer to the buffer.
Definition: netbuffer.h:74
const T * cast(size_t ofs=0) const
Access the buffer contents as a structure T at the given offset.
Definition: netbuffer.h:93
void skip()
Move the starting point of this buffer sizeof(T) bytes from the beginning.
Definition: netbuffer.h:144
NetBuffer()
Definition: netbuffer.h:45
NetBuffer(size_t size)
Definition: netbuffer.h:46
Exception thrown when some consistency check fails.
Definition: exception.h:254
bool fits(size_t ofs=0) const
Check if the buffer is long enough to contain a structure T at the given offset.
Definition: netbuffer.h:84
NetBuffer(void *buf, size_t size, bool own=true)
Definition: netbuffer.h:47
NetBuffer & operator=(const NetBuffer &buf)
Definition: netbuffer.h:63
size_t size() const
Return the buffer size.
Definition: netbuffer.h:77
NetBuffer(const NetBuffer &buf)
Definition: netbuffer.h:53
NetBuffer & operator=(const Buffer &buf)
Definition: netbuffer.h:56
const void * data(size_t ofs=0) const
Return a pointer to the buffer.
Definition: netbuffer.h:71
const NetBuffer after() const
Return another NetBuffer starting just after sizeof(T) from the beginning of this one...
Definition: netbuffer.h:123
size_t size() const
Return the buffer size.
Definition: buffer.h:149
size_t cursor
Offset in bytes of the NetBuffer start, from the beginning of the memory area we manage.
Definition: netbuffer.h:42
NetBuffer operator+(size_t ofs)
Return another NetBuffer starting ofs bytes from the beginning of this one.
Definition: netbuffer.h:103
NetBuffer(const Buffer &buf)
Definition: netbuffer.h:52
void skip(size_t t)
Move the starting point of this buffer ofs bytes from the beginning.
Definition: netbuffer.h:152
void * data()
Return a pointer to the buffer.
Definition: buffer.h:143
NetBuffer & operator+=(size_t ofs)
Move the starting point of this buffer ofs bytes from the beginning.
Definition: netbuffer.h:133
Buffer whose starting can be moved back and forth, useful to decapsulate stacked network packets...
Definition: netbuffer.h:35
Buffer & operator=(const Buffer &buf)
Definition: buffer.h:132
NetBuffer(const void *buf, size_t size)
Definition: netbuffer.h:49
Buffer()
Create a 0-lenght buffer.
Definition: buffer.h:74