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) 2009 The Georgia Institute of Technology· | 3 * Copyright (c) 2009 The Georgia Institute of Technology· |
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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return extractedBits; | 219 return extractedBits; |
220 } | 220 } |
221 | 221 |
222 uint32_t | 222 uint32_t |
223 NixVector::GetSerializedSize (void) const | 223 NixVector::GetSerializedSize (void) const |
224 { | 224 { |
225 uint32_t totalSizeInBytes = 0; | 225 uint32_t totalSizeInBytes = 0; |
226 totalSizeInBytes = sizeof (m_used) + sizeof (m_currentVectorBitSize) +· | 226 totalSizeInBytes = sizeof (m_used) + sizeof (m_currentVectorBitSize) +· |
227 sizeof (m_totalBitSize) + (4 * m_nixVector.size ()); | 227 sizeof (m_totalBitSize) + (4 * m_nixVector.size ()); |
228 | 228 |
229 // add in 4 bytes for total size | 229 return totalSizeInBytes; |
230 return totalSizeInBytes + 4; | |
231 } | 230 } |
232 | 231 |
233 uint32_t | 232 uint32_t |
234 NixVector::Serialize (uint32_t* buffer, uint32_t maxSize) const | 233 NixVector::Serialize (uint32_t* buffer, uint32_t maxSize) const |
235 { | 234 { |
236 NS_LOG_FUNCTION (this); | 235 NS_LOG_FUNCTION (this); |
237 uint32_t* p = buffer; | 236 uint32_t* p = buffer; |
238 uint32_t size = 0; | 237 uint32_t size = 0; |
239 | |
240 if (size + 4 <= maxSize) | |
241 { | |
242 size+= 4; | |
243 // add total size | |
244 *p++ = GetSerializedSize (); | |
245 } | |
246 | 238 |
247 if (size + 4 <= maxSize) | 239 if (size + 4 <= maxSize) |
248 { | 240 { |
249 size += 4; | 241 size += 4; |
250 // grab number of used bits | 242 // grab number of used bits |
251 *p++ = m_used; | 243 *p++ = m_used; |
252 } | 244 } |
253 else | 245 else |
254 { | 246 { |
255 return 0; | 247 return 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 { | 280 { |
289 return 0; | 281 return 0; |
290 } | 282 } |
291 } | 283 } |
292 | 284 |
293 // Serialized successfully | 285 // Serialized successfully |
294 return 1; | 286 return 1; |
295 } | 287 } |
296 | 288 |
297 uint32_t | 289 uint32_t |
298 NixVector::Deserialize (uint32_t* buffer, uint32_t expectedSize) | 290 NixVector::Deserialize (uint32_t* buffer, uint32_t size) |
299 { | 291 { |
300 NS_LOG_FUNCTION (this); | 292 NS_LOG_FUNCTION (this); |
301 uint32_t* p = buffer; | 293 uint32_t* p = buffer; |
302 uint32_t sizeCheck = expectedSize - 4; | 294 uint32_t sizeCheck = size - 4; |
303 | 295 |
304 NS_ASSERT (sizeCheck >= 4); | 296 NS_ASSERT (sizeCheck >= 4); |
305 m_used = *p++; | 297 m_used = *p++; |
306 sizeCheck -= 4; | 298 sizeCheck -= 4; |
307 | 299 |
308 NS_ASSERT (sizeCheck >= 4); | 300 NS_ASSERT (sizeCheck >= 4); |
309 m_currentVectorBitSize = *p++; | 301 m_currentVectorBitSize = *p++; |
310 sizeCheck -= 4; | 302 sizeCheck -= 4; |
311 | 303 |
312 NS_ASSERT (sizeCheck >= 4); | 304 NS_ASSERT (sizeCheck >= 4); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 os << 1; | 441 os << 1; |
450 } | 442 } |
451 else | 443 else |
452 { | 444 { |
453 PrintDec2BinNixFill (decimalNum / 2, bitCount, os); | 445 PrintDec2BinNixFill (decimalNum / 2, bitCount, os); |
454 os << decimalNum % 2; | 446 os << decimalNum % 2; |
455 } | 447 } |
456 } | 448 } |
457 | 449 |
458 } // namespace ns3 | 450 } // namespace ns3 |
LEFT | RIGHT |