LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2006,2007 INRIA | 3 * Copyright (c) 2006,2007 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void RemoveAtStart (uint32_t start); | 151 void RemoveAtStart (uint32_t start); |
152 void RemoveAtEnd (uint32_t end); | 152 void RemoveAtEnd (uint32_t end); |
153 | 153 |
154 uint64_t GetUid (void) const; | 154 uint64_t GetUid (void) const; |
155 | 155 |
156 uint32_t GetSerializedSize (void) const; | 156 uint32_t GetSerializedSize (void) const; |
157 | 157 |
158 ItemIterator BeginItem (Buffer buffer) const; | 158 ItemIterator BeginItem (Buffer buffer) const; |
159 | 159 |
160 // Serialization to/from raw uint8_t* | 160 // Serialization to/from raw uint8_t* |
161 uint32_t Serialize (uint8_t* i, uint32_t maxSize) const; | 161 uint32_t Serialize (uint8_t* buffer, uint32_t maxSize) const; |
162 uint32_t Deserialize (uint8_t* i, uint32_t expectedSize); | 162 uint32_t Deserialize (uint8_t* buffer, uint32_t size); |
163 ·· | 163 ·· |
164 private: | 164 private: |
165 // Helper for the raw serilization/deserialization | 165 // Helper for the raw serilization/deserialization |
166 template <typename T> static uint8_t* AddToRaw ( | 166 static uint8_t* AddToRawU8 (const uint8_t& data, |
167 const T& data, | 167 uint8_t* start, |
168 uint8_t* start, | 168 uint8_t* current, |
169 uint8_t* current, | 169 uint32_t maxSize); |
170 uint32_t maxSize) | 170 |
171 { | 171 static uint8_t* AddToRawU16 (const uint16_t& data, |
172 // First check buffer overflow | 172 uint8_t* start, |
173 if ((uint32_t)((current + sizeof (data) - start)) > maxSize) return 0; | 173 uint8_t* current, |
174 memcpy (current, &data, sizeof (data)); | 174 uint32_t maxSize); |
175 return current + sizeof (data); | 175 |
176 } | 176 static uint8_t* AddToRawU32 (const uint32_t& data, |
| 177 uint8_t* start, |
| 178 uint8_t* current, |
| 179 uint32_t maxSize); |
| 180 |
| 181 static uint8_t* AddToRawU64 (const uint64_t& data, |
| 182 uint8_t* start, |
| 183 uint8_t* current, |
| 184 uint32_t maxSize); |
| 185 |
| 186 static uint8_t* AddToRaw (const uint8_t* data, |
| 187 uint32_t dataSize, |
| 188 uint8_t* start, |
| 189 uint8_t* current, |
| 190 uint32_t maxSize); |
177 ·· | 191 ·· |
178 template <typename T> static uint8_t* AddToRaw ( | 192 static uint8_t* ReadFromRawU8 (uint8_t& data, |
179 const T* data, | 193 uint8_t* start, |
180 uint32_t dataSize, | 194 uint8_t* current, |
181 uint8_t* start, | 195 uint32_t maxSize); |
182 uint8_t* current, | 196 |
183 uint32_t maxSize) | 197 static uint8_t* ReadFromRawU16 (uint16_t& data, |
184 { | 198 uint8_t* start, |
185 // First check buffer overflow | 199 uint8_t* current, |
186 if ((uint32_t)((current + dataSize - start)) > maxSize) return 0; | 200 uint32_t maxSize); |
187 memcpy (current, data, dataSize); | 201 |
188 return current + dataSize; | 202 static uint8_t* ReadFromRawU32 (uint32_t& data, |
189 } | 203 uint8_t* start, |
190 ·· | 204 uint8_t* current, |
191 template <typename T> static uint8_t* ReadFromRaw ( | 205 uint32_t maxSize); |
192 T& data, | 206 |
193 uint8_t* start, | 207 static uint8_t* ReadFromRawU64 (uint64_t& data, |
194 uint8_t* current, | 208 uint8_t* start, |
195 uint32_t maxSize) | 209 uint8_t* current, |
196 { // First check buffer underflow | 210 uint32_t maxSize); |
197 if ((uint32_t)((current + sizeof (T) - start)) > maxSize) return 0; | |
198 memcpy(&data, current, sizeof (T)); | |
199 return current + sizeof (T); | |
200 } | |
201 ·· | |
202 | |
203 struct Data { | 211 struct Data { |
204 /* number of references to this struct Data instance. */ | 212 /* number of references to this struct Data instance. */ |
205 uint16_t m_count; | 213 uint16_t m_count; |
206 /* size (in bytes) of m_data buffer below */ | 214 /* size (in bytes) of m_data buffer below */ |
207 uint16_t m_size; | 215 uint16_t m_size; |
208 /* max of the m_used field over all objects which· | 216 /* max of the m_used field over all objects which· |
209 * reference this struct Data instance */ | 217 * reference this struct Data instance */ |
210 uint16_t m_dirtyEnd; | 218 uint16_t m_dirtyEnd; |
211 /* variable-sized buffer of bytes */ | 219 /* variable-sized buffer of bytes */ |
212 uint8_t m_data[10]; | 220 uint8_t m_data[10]; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 if (m_data->m_count == 0)· | 404 if (m_data->m_count == 0)· |
397 { | 405 { |
398 PacketMetadata::Recycle (m_data); | 406 PacketMetadata::Recycle (m_data); |
399 } | 407 } |
400 } | 408 } |
401 | 409 |
402 } // namespace ns3 | 410 } // namespace ns3 |
403 | 411 |
404 | 412 |
405 #endif /* PACKET_METADATA_H */ | 413 #endif /* PACKET_METADATA_H */ |
LEFT | RIGHT |