equal
deleted
inserted
replaced
33 */ |
33 */ |
34 virtual void read ( |
34 virtual void read ( |
35 void *ptr, //<<< where to copy |
35 void *ptr, //<<< where to copy |
36 size_t len //<<< number of bytes to copy |
36 size_t len //<<< number of bytes to copy |
37 ) = 0; |
37 ) = 0; |
|
38 |
|
39 /** |
|
40 * Abstract method to get the number of input bytes remaining. |
|
41 * |
|
42 * @return number of input bytes still readable |
|
43 */ |
|
44 virtual size_t tell_remaining (void) = 0; |
38 |
45 |
39 /** |
46 /** |
40 * Convenience function to read() and return the value of the given type |
47 * Convenience function to read() and return the value of the given type |
41 * |
48 * |
42 * @return T The value |
49 * @return T The value |
79 * @return Vector (vec_x, vec_y) |
86 * @return Vector (vec_x, vec_y) |
80 */ |
87 */ |
81 Vector read_vector (void); |
88 Vector read_vector (void); |
82 |
89 |
83 /** |
90 /** |
84 * Abstract method to get the number of input bytes remaining. |
91 * Read compressed data written with write_compressed. The given buffer must be the same size as passed to |
85 * |
92 * write_compressed. Returns the number of bytes that were decompressed into buf. |
86 * @return number of input bytes still readable |
93 */ |
87 */ |
94 size_t read_uncompressed (void *buf, size_t len); |
88 virtual size_t tell_remaining (void) = 0; |
|
89 }; |
95 }; |
90 |
96 |
91 /** |
97 /** |
92 * Write-interface for network packets |
98 * Write-interface for network packets |
93 */ |
99 */ |
94 class NetworkPacketOutput { |
100 class NetworkPacketOutput { |
|
101 protected: |
|
102 /** |
|
103 * Adjust size of the most recent write_ptr area of buf_len bytes to data_len bytes. |
|
104 */ |
|
105 virtual void write_ptr_adjust (size_t buf_len, size_t data_len) = 0; |
|
106 |
95 public: |
107 public: |
96 /** |
108 /** |
97 * Abstract method to get a pointer to \a len bytes of raw in-memory binary data, advancing the write offset |
109 * Abstract method to get a pointer to \a len bytes of raw in-memory binary data, advancing the write offset |
98 * |
110 * |
99 * @param len number of bytes to commit |
111 * @param len number of bytes to commit |
142 * This write()s the contents of the given NetworkPacketBuffer to this packet. |
154 * This write()s the contents of the given NetworkPacketBuffer to this packet. |
143 * |
155 * |
144 * @param pkt the sub-packet to write() |
156 * @param pkt the sub-packet to write() |
145 */ |
157 */ |
146 void write_packet (const NetworkPacketBuffer &pkt); |
158 void write_packet (const NetworkPacketBuffer &pkt); |
|
159 |
|
160 /** |
|
161 * This will compress the given data buffer into this packet for reading with read_compressed. The compressed |
|
162 * data will use at most write_compressed_size(len) bytes of data. |
|
163 */ |
|
164 void write_compressed (const void *ptr, uint32_t len); |
|
165 |
|
166 /** |
|
167 * Return upper bound on packet size of compressed data, including header. |
|
168 */ |
|
169 static size_t write_compressed_size (uint32_t len); |
147 }; |
170 }; |
148 |
171 |
149 /** |
172 /** |
150 * Implements an in-memory seekable buffer used by NetworkPackets |
173 * Implements an in-memory seekable buffer used by NetworkPackets |
151 * |
174 * |
228 * |
251 * |
229 * @param ptr where to copy the data from |
252 * @param ptr where to copy the data from |
230 * @param len number of bytes to copy |
253 * @param len number of bytes to copy |
231 */ |
254 */ |
232 virtual void write (const void *ptr, size_t len); |
255 virtual void write (const void *ptr, size_t len); |
|
256 |
|
257 virtual void write_ptr_adjust (size_t buf_len, size_t data_len); |
233 |
258 |
234 /** |
259 /** |
235 * Returns our data_size - read-offset |
260 * Returns our data_size - read-offset |
236 */ |
261 */ |
237 virtual size_t tell_remaining (void); |
262 virtual size_t tell_remaining (void); |