|
79 |
class PacketMetadata |
79 |
class PacketMetadata |
80 |
{ |
80 |
{ |
81 |
public: |
81 |
public: |
|
|
82 |
|
83 |
/** |
84 |
* \brief structure describing a packet metadata item |
85 |
*/ |
82 |
struct Item |
86 |
struct Item |
83 |
{ |
87 |
{ |
84 |
enum { |
88 |
enum { |
85 |
PAYLOAD, |
89 |
PAYLOAD, |
86 |
HEADER, |
90 |
HEADER, |
87 |
TRAILER |
91 |
TRAILER |
88 |
} type; |
92 |
} type; //!< metadata type |
89 |
/* true: this is a fragmented header, trailer, or, payload. |
93 |
/** |
|
|
94 |
* true: this is a fragmented header, trailer, or, payload. |
90 |
* false: this is a whole header, trailer, or, payload. |
95 |
* false: this is a whole header, trailer, or, payload. |
91 |
*/ |
96 |
*/ |
92 |
bool isFragment; |
97 |
bool isFragment; |
93 |
/* TypeId of Header or Trailer. Valid only if type is |
98 |
/** |
|
|
99 |
* TypeId of Header or Trailer. Valid only if type is |
94 |
* header or trailer. |
100 |
* header or trailer. |
95 |
*/ |
101 |
*/ |
96 |
TypeId tid; |
102 |
TypeId tid; |
97 |
/* size of item. If fragment, size of fragment. Otherwise, |
103 |
/** |
|
|
104 |
* size of item. If fragment, size of fragment. Otherwise, |
98 |
* size of original item. |
105 |
* size of original item. |
99 |
*/ |
106 |
*/ |
100 |
uint32_t currentSize; |
107 |
uint32_t currentSize; |
101 |
/* how many bytes were trimed from the start of a fragment. |
108 |
/** |
|
|
109 |
* how many bytes were trimed from the start of a fragment. |
102 |
* if isFragment is true, this field is zero. |
110 |
* if isFragment is true, this field is zero. |
103 |
*/ |
111 |
*/ |
104 |
uint32_t currentTrimedFromStart; |
112 |
uint32_t currentTrimedFromStart; |
105 |
/* how many bytes were trimed from the end of a fragment. |
113 |
/** |
|
|
114 |
* how many bytes were trimed from the end of a fragment. |
106 |
* if isFragment is true, this field is zero. |
115 |
* if isFragment is true, this field is zero. |
107 |
*/ |
116 |
*/ |
108 |
uint32_t currentTrimedFromEnd; |
117 |
uint32_t currentTrimedFromEnd; |
109 |
/* an iterator which can be fed to Deserialize. Valid only |
118 |
/** |
|
|
119 |
* an iterator which can be fed to Deserialize. Valid only |
110 |
* if isFragment and isPayload are false. |
120 |
* if isFragment and isPayload are false. |
111 |
*/ |
121 |
*/ |
112 |
Buffer::Iterator current; |
122 |
Buffer::Iterator current; |
113 |
}; |
123 |
}; |
|
|
124 |
|
125 |
/** |
126 |
* \brief Iterator class for metadata items. |
127 |
*/ |
114 |
class ItemIterator |
128 |
class ItemIterator |
115 |
{ |
129 |
{ |
116 |
public: |
130 |
public: |
|
|
131 |
/** |
132 |
* Constructor |
133 |
* \param metadata a pointer to the metadata |
134 |
* \param buffer the buffer the metadata refers to |
135 |
*/ |
117 |
ItemIterator (const PacketMetadata *metadata, Buffer buffer); |
136 |
ItemIterator (const PacketMetadata *metadata, Buffer buffer); |
|
|
137 |
/** |
138 |
* \brief Checks if there is another metadata item |
139 |
* \returns true if there is another item |
140 |
*/ |
118 |
bool HasNext (void) const; |
141 |
bool HasNext (void) const; |
|
|
142 |
/** |
143 |
* \brief Retrieve the next metadata item |
144 |
* \returns the next metadata item |
145 |
*/ |
119 |
Item Next (void); |
146 |
Item Next (void); |
120 |
private: |
147 |
private: |
121 |
const PacketMetadata *m_metadata; |
148 |
const PacketMetadata *m_metadata; //!< pointer to the metadata |
122 |
Buffer m_buffer; |
149 |
Buffer m_buffer; //!< buffer the metadata refers to |
123 |
uint16_t m_current; |
150 |
uint16_t m_current; //!< current position |
124 |
uint32_t m_offset; |
151 |
uint32_t m_offset; //!< offset |
125 |
bool m_hasReadTail; |
152 |
bool m_hasReadTail; //!< true if the metadata tail has been read |
126 |
}; |
153 |
}; |
127 |
|
154 |
|
|
|
155 |
/** |
156 |
* \brief Enable the packet metadata |
157 |
*/ |
128 |
static void Enable (void); |
158 |
static void Enable (void); |
|
|
159 |
/** |
160 |
* \brief Enable the packet metadata checking |
161 |
*/ |
129 |
static void EnableChecking (void); |
162 |
static void EnableChecking (void); |
130 |
|
163 |
|
|
|
164 |
/** |
165 |
* Constructor |
166 |
* \param uid packet uid |
167 |
* \param size size of the header |
168 |
*/ |
131 |
inline PacketMetadata (uint64_t uid, uint32_t size); |
169 |
inline PacketMetadata (uint64_t uid, uint32_t size); |
|
|
170 |
/** |
171 |
* Copy constructor |
172 |
* \param o the object to copy |
173 |
*/ |
132 |
inline PacketMetadata (PacketMetadata const &o); |
174 |
inline PacketMetadata (PacketMetadata const &o); |
|
|
175 |
/** |
176 |
* Basic assignment |
177 |
* \param o the object to copy |
178 |
* \return a copied object |
179 |
*/ |
133 |
inline PacketMetadata &operator = (PacketMetadata const& o); |
180 |
inline PacketMetadata &operator = (PacketMetadata const& o); |
134 |
inline ~PacketMetadata (); |
181 |
inline ~PacketMetadata (); |
135 |
|
182 |
|
|
|
183 |
/** |
184 |
* Add an header |
185 |
* \param header header to add |
186 |
* \param size header serialized size |
187 |
*/ |
136 |
void AddHeader (Header const &header, uint32_t size); |
188 |
void AddHeader (Header const &header, uint32_t size); |
|
|
189 |
/** |
190 |
* Remove an header |
191 |
* \param header header to remove |
192 |
* \param size header serialized size |
193 |
*/ |
137 |
void RemoveHeader (Header const &header, uint32_t size); |
194 |
void RemoveHeader (Header const &header, uint32_t size); |
138 |
|
195 |
|
|
|
196 |
/** |
197 |
* Add a trailer |
198 |
* \param trailer trailer to add |
199 |
* \param size trailer serialized size |
200 |
*/ |
139 |
void AddTrailer (Trailer const &trailer, uint32_t size); |
201 |
void AddTrailer (Trailer const &trailer, uint32_t size); |
|
|
202 |
/** |
203 |
* Remove a trailer |
204 |
* \param trailer trailer to remove |
205 |
* \param size trailer serialized size |
206 |
*/ |
140 |
void RemoveTrailer (Trailer const &trailer, uint32_t size); |
207 |
void RemoveTrailer (Trailer const &trailer, uint32_t size); |
141 |
|
208 |
|
142 |
/** |
209 |
/** |
143 |
* \param start the amount of stuff to remove from the start |
210 |
* \param start the amount of stuff to remove from the start |
144 |
* \param end the amount of stuff to remove from the end |
211 |
* \param end the amount of stuff to remove from the end |
|
|
212 |
* \return the fragment's metadata |
145 |
* |
213 |
* |
146 |
* Calling this method is equivalent to calling RemoveAtStart (start) |
214 |
* Calling this method is equivalent to calling RemoveAtStart (start) |
147 |
* and then, RemoveAtEnd (end). |
215 |
* and then, RemoveAtEnd (end). |
148 |
*/ |
216 |
*/ |
149 |
PacketMetadata CreateFragment (uint32_t start, uint32_t end) const; |
217 |
PacketMetadata CreateFragment (uint32_t start, uint32_t end) const; |
|
|
218 |
|
219 |
/** |
220 |
* Add a metadata at the metadata start |
221 |
* \param o the metadata to add |
222 |
*/ |
150 |
void AddAtEnd (PacketMetadata const&o); |
223 |
void AddAtEnd (PacketMetadata const&o); |
|
|
224 |
/** |
225 |
* Add some padding at the end |
226 |
* \param end size of padding |
227 |
*/ |
151 |
void AddPaddingAtEnd (uint32_t end); |
228 |
void AddPaddingAtEnd (uint32_t end); |
|
|
229 |
/** |
230 |
* Remove a chunk of metadata at the metadata start |
231 |
* \param start the size of metadata to remove |
232 |
*/ |
152 |
void RemoveAtStart (uint32_t start); |
233 |
void RemoveAtStart (uint32_t start); |
|
|
234 |
/** |
235 |
* Remove a chunk of metadata at the metadata end |
236 |
* \param end the size of metadata to remove |
237 |
*/ |
153 |
void RemoveAtEnd (uint32_t end); |
238 |
void RemoveAtEnd (uint32_t end); |
154 |
|
239 |
|
|
|
240 |
/** |
241 |
* Get the packet Uid |
242 |
* \return the packet Uid |
243 |
*/ |
155 |
uint64_t GetUid (void) const; |
244 |
uint64_t GetUid (void) const; |
156 |
|
245 |
|
|
|
246 |
/** |
247 |
* Get the metadata serialized size |
248 |
* \return the seralized size |
249 |
*/ |
157 |
uint32_t GetSerializedSize (void) const; |
250 |
uint32_t GetSerializedSize (void) const; |
158 |
|
251 |
|
|
|
252 |
/** |
253 |
* Initialize the item iterator to the buffer begin |
254 |
*/ |
159 |
ItemIterator BeginItem (Buffer buffer) const; |
255 |
ItemIterator BeginItem (Buffer buffer) const; |
160 |
|
256 |
|
161 |
// Serialization to/from raw uint8_t* |
257 |
/** |
|
|
258 |
* Serialization to raw uint8_t* |
259 |
* \param buffer the buffer to serialize to |
260 |
* \param maxSize the maximum serialization size |
261 |
* \return 1 on success, 0 on failure |
262 |
*/ |
162 |
uint32_t Serialize (uint8_t* buffer, uint32_t maxSize) const; |
263 |
uint32_t Serialize (uint8_t* buffer, uint32_t maxSize) const; |
|
|
264 |
/** |
265 |
* Deserialization from raw uint8_t* |
266 |
* \param buffer the buffer to deserialize from |
267 |
* \param size the size |
268 |
* \return 1 on success, 0 on failure |
269 |
*/ |
163 |
uint32_t Deserialize (const uint8_t* buffer, uint32_t size); |
270 |
uint32_t Deserialize (const uint8_t* buffer, uint32_t size); |
164 |
|
271 |
|
165 |
private: |
272 |
private: |
166 |
// Helper for the raw serilization/deserialization |
273 |
/** |
|
|
274 |
* Helper for the raw serilization |
275 |
* \param data the buffer to write to |
276 |
* \param start start index |
277 |
* \param current current index |
278 |
* \param maxSize maximum size |
279 |
* \return updated current index |
280 |
*/ |
167 |
static uint8_t* AddToRawU8 (const uint8_t& data, |
281 |
static uint8_t* AddToRawU8 (const uint8_t& data, |
168 |
uint8_t* start, |
282 |
uint8_t* start, |
169 |
uint8_t* current, |
283 |
uint8_t* current, |
170 |
uint32_t maxSize); |
284 |
uint32_t maxSize); |
171 |
|
285 |
|
|
|
286 |
/** |
287 |
* Helper for the raw serilization |
288 |
* \param data the buffer to write to |
289 |
* \param start start index |
290 |
* \param current current index |
291 |
* \param maxSize maximum size |
292 |
* \return updated current index |
293 |
*/ |
172 |
static uint8_t* AddToRawU16 (const uint16_t& data, |
294 |
static uint8_t* AddToRawU16 (const uint16_t& data, |
173 |
uint8_t* start, |
295 |
uint8_t* start, |
174 |
uint8_t* current, |
296 |
uint8_t* current, |
175 |
uint32_t maxSize); |
297 |
uint32_t maxSize); |
176 |
|
298 |
|
|
|
299 |
/** |
300 |
* Helper for the raw serilization |
301 |
* \param data the buffer to write to |
302 |
* \param start start index |
303 |
* \param current current index |
304 |
* \param maxSize maximum size |
305 |
* \return updated current index |
306 |
*/ |
177 |
static uint8_t* AddToRawU32 (const uint32_t& data, |
307 |
static uint8_t* AddToRawU32 (const uint32_t& data, |
178 |
uint8_t* start, |
308 |
uint8_t* start, |
179 |
uint8_t* current, |
309 |
uint8_t* current, |
180 |
uint32_t maxSize); |
310 |
uint32_t maxSize); |
181 |
|
311 |
|
|
|
312 |
/** |
313 |
* Helper for the raw serilization |
314 |
* \param data the buffer to write to |
315 |
* \param start start index |
316 |
* \param current current index |
317 |
* \param maxSize maximum size |
318 |
* \return updated current index |
319 |
*/ |
182 |
static uint8_t* AddToRawU64 (const uint64_t& data, |
320 |
static uint8_t* AddToRawU64 (const uint64_t& data, |
183 |
uint8_t* start, |
321 |
uint8_t* start, |
184 |
uint8_t* current, |
322 |
uint8_t* current, |
185 |
uint32_t maxSize); |
323 |
uint32_t maxSize); |
186 |
|
324 |
|
|
|
325 |
/** |
326 |
* Helper for the raw serilization |
327 |
* \param data the buffer to write to |
328 |
* \param dataSize the data size to write to |
329 |
* \param start start index |
330 |
* \param current current index |
331 |
* \param maxSize maximum size |
332 |
* \return updated current index |
333 |
*/ |
187 |
static uint8_t* AddToRaw (const uint8_t* data, |
334 |
static uint8_t* AddToRaw (const uint8_t* data, |
188 |
uint32_t dataSize, |
335 |
uint32_t dataSize, |
189 |
uint8_t* start, |
336 |
uint8_t* start, |
190 |
uint8_t* current, |
337 |
uint8_t* current, |
191 |
uint32_t maxSize); |
338 |
uint32_t maxSize); |
192 |
|
339 |
|
|
|
340 |
/** |
341 |
* Helper for the raw deserilization |
342 |
* \param data the buffer to read from |
343 |
* \param start start index |
344 |
* \param current current index |
345 |
* \param maxSize maximum size |
346 |
* \return updated current index |
347 |
*/ |
193 |
static uint8_t* ReadFromRawU8 (uint8_t& data, |
348 |
static uint8_t* ReadFromRawU8 (uint8_t& data, |
194 |
const uint8_t* start, |
349 |
const uint8_t* start, |
195 |
const uint8_t* current, |
350 |
const uint8_t* current, |
196 |
uint32_t maxSize); |
351 |
uint32_t maxSize); |
197 |
|
352 |
|
|
|
353 |
/** |
354 |
* Helper for the raw deserilization |
355 |
* \param data the buffer to read from |
356 |
* \param start start index |
357 |
* \param current current index |
358 |
* \param maxSize maximum size |
359 |
* \return updated current index |
360 |
*/ |
198 |
static uint8_t* ReadFromRawU16 (uint16_t& data, |
361 |
static uint8_t* ReadFromRawU16 (uint16_t& data, |
199 |
const uint8_t* start, |
362 |
const uint8_t* start, |
200 |
const uint8_t* current, |
363 |
const uint8_t* current, |
201 |
uint32_t maxSize); |
364 |
uint32_t maxSize); |
202 |
|
365 |
|
|
|
366 |
/** |
367 |
* Helper for the raw deserilization |
368 |
* \param data the buffer to read from |
369 |
* \param start start index |
370 |
* \param current current index |
371 |
* \param maxSize maximum size |
372 |
* \return updated current index |
373 |
*/ |
203 |
static uint8_t* ReadFromRawU32 (uint32_t& data, |
374 |
static uint8_t* ReadFromRawU32 (uint32_t& data, |
204 |
const uint8_t* start, |
375 |
const uint8_t* start, |
205 |
const uint8_t* current, |
376 |
const uint8_t* current, |
206 |
uint32_t maxSize); |
377 |
uint32_t maxSize); |
207 |
|
378 |
|
|
|
379 |
/** |
380 |
* Helper for the raw deserilization |
381 |
* \param data the buffer to read from |
382 |
* \param start start index |
383 |
* \param current current index |
384 |
* \param maxSize maximum size |
385 |
* \return updated current index |
386 |
*/ |
208 |
static uint8_t* ReadFromRawU64 (uint64_t& data, |
387 |
static uint8_t* ReadFromRawU64 (uint64_t& data, |
209 |
const uint8_t* start, |
388 |
const uint8_t* start, |
210 |
const uint8_t* current, |
389 |
const uint8_t* current, |
|
216 |
*/ |
395 |
*/ |
217 |
#define PACKET_METADATA_DATA_M_DATA_SIZE 8 |
396 |
#define PACKET_METADATA_DATA_M_DATA_SIZE 8 |
218 |
|
397 |
|
|
|
398 |
/** |
399 |
* Data structure |
400 |
*/ |
219 |
struct Data { |
401 |
struct Data { |
220 |
/* number of references to this struct Data instance. */ |
402 |
/** number of references to this struct Data instance. */ |
221 |
uint32_t m_count; |
403 |
uint32_t m_count; |
222 |
/* size (in bytes) of m_data buffer below */ |
404 |
/** size (in bytes) of m_data buffer below */ |
223 |
uint16_t m_size; |
405 |
uint16_t m_size; |
224 |
/* max of the m_used field over all objects which |
406 |
/** max of the m_used field over all objects which |
225 |
* reference this struct Data instance */ |
407 |
* reference this struct Data instance */ |
226 |
uint16_t m_dirtyEnd; |
408 |
uint16_t m_dirtyEnd; |
227 |
/* variable-sized buffer of bytes */ |
409 |
/** variable-sized buffer of bytes */ |
228 |
uint8_t m_data[PACKET_METADATA_DATA_M_DATA_SIZE]; |
410 |
uint8_t m_data[PACKET_METADATA_DATA_M_DATA_SIZE]; |
229 |
}; |
411 |
}; |
230 |
/* Note that since the next and prev fields are 16 bit integers |
412 |
/* Note that since the next and prev fields are 16 bit integers |
|
233 |
only a limited number of elements can be stored in |
415 |
only a limited number of elements can be stored in |
234 |
a m_data byte buffer. |
416 |
a m_data byte buffer. |
235 |
*/ |
417 |
*/ |
|
|
418 |
/** |
419 |
* SmallItem structure |
420 |
*/ |
236 |
struct SmallItem { |
421 |
struct SmallItem { |
237 |
/* offset (in bytes) from start of m_data buffer |
422 |
/** offset (in bytes) from start of m_data buffer |
238 |
to next element in linked list. value is 0xffff |
423 |
to next element in linked list. value is 0xffff |
239 |
if next element does not exist. |
424 |
if next element does not exist. |
240 |
stored as a fixed-size 16 bit integer. |
425 |
stored as a fixed-size 16 bit integer. |
241 |
*/ |
426 |
*/ |
242 |
uint16_t next; |
427 |
uint16_t next; |
243 |
/* offset (in bytes) from start of m_data buffer |
428 |
/** offset (in bytes) from start of m_data buffer |
244 |
to previous element in linked list. value is 0xffff |
429 |
to previous element in linked list. value is 0xffff |
245 |
if previous element does not exist. |
430 |
if previous element does not exist. |
246 |
stored as a fixed-size 16 bit integer. |
431 |
stored as a fixed-size 16 bit integer. |
247 |
*/ |
432 |
*/ |
248 |
uint16_t prev; |
433 |
uint16_t prev; |
249 |
/* the high 31 bits of this field identify the |
434 |
/** the high 31 bits of this field identify the |
250 |
type of the header or trailer represented by |
435 |
type of the header or trailer represented by |
251 |
this item: the value zero represents payload. |
436 |
this item: the value zero represents payload. |
252 |
If the low bit of this uid is one, an ExtraItem |
437 |
If the low bit of this uid is one, an ExtraItem |
|
254 |
stored as a variable-size 32 bit integer. |
439 |
stored as a variable-size 32 bit integer. |
255 |
*/ |
440 |
*/ |
256 |
uint32_t typeUid; |
441 |
uint32_t typeUid; |
257 |
/* the size (in bytes) of the header or trailer represented |
442 |
/** the size (in bytes) of the header or trailer represented |
258 |
by this element. |
443 |
by this element. |
259 |
stored as a variable-size 32 bit integer. |
444 |
stored as a variable-size 32 bit integer. |
260 |
*/ |
445 |
*/ |
261 |
uint32_t size; |
446 |
uint32_t size; |
262 |
/* this field tries to uniquely identify each header or |
447 |
/** this field tries to uniquely identify each header or |
263 |
trailer _instance_ while the typeUid field uniquely |
448 |
trailer _instance_ while the typeUid field uniquely |
264 |
identifies each header or trailer _type_. This field |
449 |
identifies each header or trailer _type_. This field |
265 |
is used to test whether two items are equal in the sense |
450 |
is used to test whether two items are equal in the sense |
|
273 |
*/ |
458 |
*/ |
274 |
uint16_t chunkUid; |
459 |
uint16_t chunkUid; |
275 |
}; |
460 |
}; |
|
|
461 |
|
462 |
/** |
463 |
* ExtraItem structure |
464 |
*/ |
276 |
struct ExtraItem { |
465 |
struct ExtraItem { |
277 |
/* offset (in bytes) from start of original header to |
466 |
/** offset (in bytes) from start of original header to |
278 |
the start of the fragment still present. |
467 |
the start of the fragment still present. |
279 |
stored as a variable-size 32 bit integer. |
468 |
stored as a variable-size 32 bit integer. |
280 |
*/ |
469 |
*/ |
281 |
uint32_t fragmentStart; |
470 |
uint32_t fragmentStart; |
282 |
/* offset (in bytes) from start of original header to |
471 |
/** offset (in bytes) from start of original header to |
283 |
the end of the fragment still present. |
472 |
the end of the fragment still present. |
284 |
stored as a variable-size 32 bit integer. |
473 |
stored as a variable-size 32 bit integer. |
285 |
*/ |
474 |
*/ |
286 |
uint32_t fragmentEnd; |
475 |
uint32_t fragmentEnd; |
287 |
/* the packetUid of the packet in which this header or trailer |
476 |
/** the packetUid of the packet in which this header or trailer |
288 |
was first added. It could be different from the m_packetUid |
477 |
was first added. It could be different from the m_packetUid |
289 |
field if the user has aggregated multiple packets into one. |
478 |
field if the user has aggregated multiple packets into one. |
290 |
stored as a fixed-size 64 bit integer. |
479 |
stored as a fixed-size 64 bit integer. |
|
292 |
uint64_t packetUid; |
481 |
uint64_t packetUid; |
293 |
}; |
482 |
}; |
294 |
|
483 |
|
|
|
484 |
/** |
485 |
* Class to hold all the metadata |
486 |
*/ |
295 |
class DataFreeList : public std::vector<struct Data *> |
487 |
class DataFreeList : public std::vector<struct Data *> |
296 |
{ |
488 |
{ |
297 |
public: |
489 |
public: |
|
303 |
|
495 |
|
304 |
PacketMetadata (); |
496 |
PacketMetadata (); |
305 |
|
497 |
|
|
|
498 |
/** |
499 |
* Add a SmallItem |
500 |
* \param item the SmallItem to add |
501 |
* \return added size |
502 |
*/ |
306 |
inline uint16_t AddSmall (const PacketMetadata::SmallItem *item); |
503 |
inline uint16_t AddSmall (const PacketMetadata::SmallItem *item); |
|
|
504 |
/** |
505 |
* Add a "Big" Item (a SmallItem plus an ExtraItem) |
506 |
* \param head the head |
507 |
* \param tail the tail |
508 |
* \param item the SmallItem to add |
509 |
* \param extraItem the ExtraItem to add |
510 |
* \return added size |
511 |
*/ |
307 |
uint16_t AddBig (uint32_t head, uint32_t tail, |
512 |
uint16_t AddBig (uint32_t head, uint32_t tail, |
308 |
const PacketMetadata::SmallItem *item, |
513 |
const PacketMetadata::SmallItem *item, |
309 |
const PacketMetadata::ExtraItem *extraItem); |
514 |
const PacketMetadata::ExtraItem *extraItem); |
|
|
515 |
/** |
516 |
* Replace the tail |
517 |
* \param item the item data to write |
518 |
* \param extraItem the extra item data to write |
519 |
* \param available the number of bytes which can |
520 |
* be written without having to rewrite the buffer entirely. |
521 |
*/ |
310 |
void ReplaceTail (PacketMetadata::SmallItem *item, |
522 |
void ReplaceTail (PacketMetadata::SmallItem *item, |
311 |
PacketMetadata::ExtraItem *extraItem, |
523 |
PacketMetadata::ExtraItem *extraItem, |
312 |
uint32_t available); |
524 |
uint32_t available); |
|
|
525 |
/** |
526 |
* Update the head |
527 |
* \param written the used bytes |
528 |
*/ |
313 |
inline void UpdateHead (uint16_t written); |
529 |
inline void UpdateHead (uint16_t written); |
|
|
530 |
/** |
531 |
* Update the tail |
532 |
* \param written the used bytes |
533 |
*/ |
314 |
inline void UpdateTail (uint16_t written); |
534 |
inline void UpdateTail (uint16_t written); |
|
|
535 |
|
536 |
/** |
537 |
* Get the ULEB128 (Unsigned Little Endian Base 128) size |
538 |
* \param value the value |
539 |
* \returns the value's ULEB128 size |
540 |
*/ |
315 |
inline uint32_t GetUleb128Size (uint32_t value) const; |
541 |
inline uint32_t GetUleb128Size (uint32_t value) const; |
|
|
542 |
/** |
543 |
* Read a ULEB128 (Unsigned Little Endian Base 128) coded number |
544 |
* \param pBuffer the buffer to read from |
545 |
* \returns the value |
546 |
*/ |
316 |
uint32_t ReadUleb128 (const uint8_t **pBuffer) const; |
547 |
uint32_t ReadUleb128 (const uint8_t **pBuffer) const; |
|
|
548 |
/** |
549 |
* Append a 16-bit value to the buffer |
550 |
* \param value the value to add |
551 |
* \param buffer the buffer to write to |
552 |
*/ |
317 |
inline void Append16 (uint16_t value, uint8_t *buffer); |
553 |
inline void Append16 (uint16_t value, uint8_t *buffer); |
|
|
554 |
/** |
555 |
* Append a 32-bit value to the buffer |
556 |
* \param value the value to add |
557 |
* \param buffer the buffer to write to |
558 |
*/ |
318 |
inline void Append32 (uint32_t value, uint8_t *buffer); |
559 |
inline void Append32 (uint32_t value, uint8_t *buffer); |
|
|
560 |
/** |
561 |
* Append a value to the buffer |
562 |
* \param value the value to add |
563 |
* \param buffer the buffer to write to |
564 |
*/ |
319 |
inline void AppendValue (uint32_t value, uint8_t *buffer); |
565 |
inline void AppendValue (uint32_t value, uint8_t *buffer); |
|
|
566 |
/** |
567 |
* \brief Append a value to the buffer - extra |
568 |
* |
569 |
* This function is called by AppendValue |
570 |
* |
571 |
* \param value the value to add |
572 |
* \param buffer the buffer to write to |
573 |
*/ |
320 |
void AppendValueExtra (uint32_t value, uint8_t *buffer); |
574 |
void AppendValueExtra (uint32_t value, uint8_t *buffer); |
|
|
575 |
|
576 |
/** |
577 |
* Reserve space |
578 |
* \param n space to reserve |
579 |
*/ |
321 |
inline void Reserve (uint32_t n); |
580 |
inline void Reserve (uint32_t n); |
|
|
581 |
/** |
582 |
* Reserve space and make a metadata copy |
583 |
* \param n space to reserve |
584 |
*/ |
322 |
void ReserveCopy (uint32_t n); |
585 |
void ReserveCopy (uint32_t n); |
|
|
586 |
|
587 |
/** |
588 |
* Get the total size used by the metadata |
589 |
*/ |
323 |
uint32_t GetTotalSize (void) const; |
590 |
uint32_t GetTotalSize (void) const; |
|
|
591 |
|
592 |
/** |
593 |
* Read items |
594 |
* \param current the offset we should start reading the data from |
595 |
* \param item pointer to where we should store the data to return to the caller |
596 |
* \param extraItem pointer to where we should store the data to return to the caller |
597 |
* \returns the number of bytes read. |
598 |
*/ |
324 |
uint32_t ReadItems (uint16_t current, |
599 |
uint32_t ReadItems (uint16_t current, |
325 |
struct PacketMetadata::SmallItem *item, |
600 |
struct PacketMetadata::SmallItem *item, |
326 |
struct PacketMetadata::ExtraItem *extraItem) const; |
601 |
struct PacketMetadata::ExtraItem *extraItem) const; |
|
|
602 |
/** |
603 |
* Add an header |
604 |
* \param uid header's uid to add |
605 |
* \param size header serialized size |
606 |
*/ |
327 |
void DoAddHeader (uint32_t uid, uint32_t size); |
607 |
void DoAddHeader (uint32_t uid, uint32_t size); |
|
|
608 |
/** |
609 |
* Check if the metadata state is ok |
610 |
* \returns true if the internal state is ok |
611 |
*/ |
328 |
bool IsStateOk (void) const; |
612 |
bool IsStateOk (void) const; |
|
|
613 |
/** |
614 |
* Check if the position is valid |
615 |
* \param pointer the position to check |
616 |
* \returns true if the position is valid |
617 |
*/ |
329 |
bool IsPointerOk (uint16_t pointer) const; |
618 |
bool IsPointerOk (uint16_t pointer) const; |
|
|
619 |
/** |
620 |
* Check if the position is valid |
621 |
* \param pointer the position to check |
622 |
* \returns true if the position is valid |
623 |
*/ |
330 |
bool IsSharedPointerOk (uint16_t pointer) const; |
624 |
bool IsSharedPointerOk (uint16_t pointer) const; |
331 |
|
625 |
|
332 |
|
626 |
/** |
|
|
627 |
* \brief Recycle the buffer memory |
628 |
* \param data the buffer data storage |
629 |
*/ |
630 |
static void Recycle (struct PacketMetadata::Data *data); |
631 |
/** |
632 |
* \brief Create a buffer data storage |
633 |
* \param size the storage size to create |
634 |
* \returns a pointer to the created buffer storage |
635 |
*/ |
333 |
static struct PacketMetadata::Data *Create (uint32_t size); |
636 |
static struct PacketMetadata::Data *Create (uint32_t size); |
334 |
static void Recycle (struct PacketMetadata::Data *data); |
637 |
/** |
|
|
638 |
* \brief Allocate a buffer data storage |
639 |
* \param n the storage size to create |
640 |
* \returns a pointer to the allocated buffer storage |
641 |
*/ |
335 |
static struct PacketMetadata::Data *Allocate (uint32_t n); |
642 |
static struct PacketMetadata::Data *Allocate (uint32_t n); |
|
|
643 |
/** |
644 |
* \brief Deallocate the buffer memory |
645 |
* \param data the buffer data storage |
646 |
*/ |
336 |
static void Deallocate (struct PacketMetadata::Data *data); |
647 |
static void Deallocate (struct PacketMetadata::Data *data); |
337 |
|
648 |
|
338 |
static DataFreeList m_freeList; |
649 |
static DataFreeList m_freeList; //!< the metadata data storage |
339 |
static bool m_enable; |
650 |
static bool m_enable; //!< Enable the packet metadata |
340 |
static bool m_enableChecking; |
651 |
static bool m_enableChecking; //!< Enable the packet metadata checking |
341 |
|
652 |
|
342 |
// set to true when adding metadata to a packet is skipped because |
653 |
/** |
343 |
// m_enable is false; used to detect enabling of metadata in the |
654 |
* Set to true when adding metadata to a packet is skipped because |
344 |
// middle of a simulation, which isn't allowed. |
655 |
* m_enable is false; used to detect enabling of metadata in the |
|
|
656 |
* middle of a simulation, which isn't allowed. |
657 |
*/ |
345 |
static bool m_metadataSkipped; |
658 |
static bool m_metadataSkipped; |
346 |
|
659 |
|
347 |
static uint32_t m_maxSize; |
660 |
static uint32_t m_maxSize; //!< maximum metadata size |
348 |
static uint16_t m_chunkUid; |
661 |
static uint16_t m_chunkUid; //!< Chunk Uid |
349 |
|
662 |
|
350 |
struct Data *m_data; |
663 |
struct Data *m_data; //!< Metadata storage |
351 |
/** |
664 |
/* |
352 |
head -(next)-> tail |
665 |
head -(next)-> tail |
353 |
^ | |
666 |
^ | |
354 |
\---(prev)---| |
667 |
\---(prev)---| |
355 |
*/ |
668 |
*/ |
356 |
uint16_t m_head; |
669 |
uint16_t m_head; //!< list head |
357 |
uint16_t m_tail; |
670 |
uint16_t m_tail; //!< list tail |
358 |
uint16_t m_used; |
671 |
uint16_t m_used; //!< used portion |
359 |
uint64_t m_packetUid; |
672 |
uint64_t m_packetUid; //!< packet Uid |
360 |
}; |
673 |
}; |
361 |
|
674 |
|
362 |
} // namespace ns3 |
675 |
} // namespace ns3 |