--- a/src/Network/Packet.hh Tue Jan 13 20:21:28 2009 +0200
+++ b/src/Network/Packet.hh Tue Jan 13 21:14:12 2009 +0200
@@ -35,6 +35,13 @@
void *ptr, //<<< where to copy
size_t len //<<< number of bytes to copy
) = 0;
+
+ /**
+ * Abstract method to get the number of input bytes remaining.
+ *
+ * @return number of input bytes still readable
+ */
+ virtual size_t tell_remaining (void) = 0;
/**
* Convenience function to read() and return the value of the given type
@@ -81,17 +88,22 @@
Vector read_vector (void);
/**
- * Abstract method to get the number of input bytes remaining.
- *
- * @return number of input bytes still readable
+ * Read compressed data written with write_compressed. The given buffer must be the same size as passed to
+ * write_compressed. Returns the number of bytes that were decompressed into buf.
*/
- virtual size_t tell_remaining (void) = 0;
+ size_t read_uncompressed (void *buf, size_t len);
};
/**
* Write-interface for network packets
*/
class NetworkPacketOutput {
+ protected:
+ /**
+ * Adjust size of the most recent write_ptr area of buf_len bytes to data_len bytes.
+ */
+ virtual void write_ptr_adjust (size_t buf_len, size_t data_len) = 0;
+
public:
/**
* Abstract method to get a pointer to \a len bytes of raw in-memory binary data, advancing the write offset
@@ -144,6 +156,17 @@
* @param pkt the sub-packet to write()
*/
void write_packet (const NetworkPacketBuffer &pkt);
+
+ /**
+ * This will compress the given data buffer into this packet for reading with read_compressed. The compressed
+ * data will use at most write_compressed_size(len) bytes of data.
+ */
+ void write_compressed (const void *ptr, uint32_t len);
+
+ /**
+ * Return upper bound on packet size of compressed data, including header.
+ */
+ static size_t write_compressed_size (uint32_t len);
};
/**
@@ -231,6 +254,8 @@
*/
virtual void write (const void *ptr, size_t len);
+ virtual void write_ptr_adjust (size_t buf_len, size_t data_len);
+
/**
* Returns our data_size - read-offset
*/