From ec6e1ff8bc85040f2ecc3225f6ec91cbfd13a72c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sat, 10 Feb 2007 10:24:36 +0100 Subject: [PATCH] add packet constructor which accepts payload buffer. --- src/common/packet.cc | 10 ++++++++++ src/common/packet.h | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/common/packet.cc b/src/common/packet.cc index d24c97f32..f6df542a2 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -38,6 +38,16 @@ Packet::Packet (uint32_t size) { m_global_uid++; } +Packet::Packet (uint8_t const*buffer, uint32_t size) + : m_buffer (), + m_uid (m_global_uid) +{ + m_global_uid++; + m_buffer.AddAtStart (size); + Buffer::Iterator i = m_buffer.Begin (); + i.Write (buffer, size); +} + Packet::Packet (Buffer buffer, Tags tags, uint32_t uid) : m_buffer (buffer), m_tags (tags), diff --git a/src/common/packet.h b/src/common/packet.h index e3f21f902..917945bdf 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -103,6 +103,15 @@ public: * \param size the size of the zero-filled payload */ Packet (uint32_t size); + /** + * Create a packet with payload filled with the content + * of this buffer. The input data is copied: the input + * buffer is untouched. + * + * \param buffer the data to store in the packet. + * \param size the size of the input buffer. + */ + Packet (uint8_t const*buffer, uint32_t size); /** * Create a new packet which contains a fragment of the original * packet. The returned packet shares the same uid as this packet.