Ilya Moiseenko | 59c6221 | 2011-08-04 19:04:24 -0700 | [diff] [blame^] | 1 | // |
| 2 | // ndn_nonceheader.cpp |
| 3 | // Abstraction |
| 4 | // |
| 5 | // Created by Ilya Moiseenko on 04.08.11. |
| 6 | // Copyright 2011 UCLA. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | #include "ndn_nonceheader.h" |
| 10 | |
| 11 | |
| 12 | namespace ns3 |
| 13 | { |
| 14 | namespace NDNabstraction |
| 15 | { |
| 16 | NS_OBJECT_ENSURE_REGISTERED (NonceHeader); |
| 17 | |
| 18 | NonceHeader::NonceHeader() |
| 19 | { |
| 20 | m_value = 0; |
| 21 | } |
| 22 | |
| 23 | NonceHeader::NonceHeader (uint32_t nonce) |
| 24 | { |
| 25 | m_value = nonce; |
| 26 | } |
| 27 | |
| 28 | TypeId |
| 29 | NonceHeader::GetTypeId () |
| 30 | { |
| 31 | static TypeId tid = TypeId ("ns3::NDNabstraction::NonceHeader") |
| 32 | .SetParent<Header> () |
| 33 | .AddConstructor<NonceHeader> () |
| 34 | ; |
| 35 | return tid; |
| 36 | } |
| 37 | |
| 38 | TypeId |
| 39 | NonceHeader::GetInstanceTypeId () const |
| 40 | { |
| 41 | return GetTypeId (); |
| 42 | } |
| 43 | |
| 44 | uint32_t |
| 45 | NonceHeader::GetSerializedSize () const |
| 46 | { |
| 47 | return 4; |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | NonceHeader::Serialize (Buffer::Iterator i) const |
| 52 | { |
| 53 | i.WriteU32 ((uint32_t) m_value); |
| 54 | } |
| 55 | |
| 56 | uint32_t |
| 57 | NonceHeader::Deserialize (Buffer::Iterator start) |
| 58 | { |
| 59 | Buffer::Iterator i = start; |
| 60 | m_value = i.ReadU32 (); |
| 61 | |
| 62 | uint32_t dist = i.GetDistanceFrom (start); |
| 63 | NS_ASSERT (dist == GetSerializedSize ()); |
| 64 | return dist; |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | NonceHeader::Print (std::ostream &os) const |
| 69 | { |
| 70 | os << m_value; |
| 71 | } |
| 72 | |
| 73 | uint32_t |
| 74 | NonceHeader::GetValue() |
| 75 | { |
| 76 | return m_value; |
| 77 | } |
| 78 | } |
| 79 | } |