Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 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 |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifndef _CCNX_ENCODING_HELPER_H_ |
| 22 | #define _CCNX_ENCODING_HELPER_H_ |
| 23 | |
| 24 | #include <sys/types.h> |
| 25 | |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 26 | #include "ccnb-parser/ccnb-parser-common.h" |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 27 | #include "ns3/ptr.h" |
| 28 | #include "ns3/nstime.h" |
| 29 | #include "ns3/buffer.h" |
| 30 | |
| 31 | namespace ns3 { |
| 32 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 33 | class CcnxNameComponents; |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 34 | |
| 35 | class CcnxInterestHeader; |
| 36 | class CcnxContentObjectHeader; |
| 37 | |
| 38 | /** |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 39 | * \brief Helper to encode/decode ccnb formatted CCNx message |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 40 | * |
| 41 | */ |
| 42 | class CcnxEncodingHelper |
| 43 | { |
| 44 | public: |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 45 | /** |
| 46 | * \brief Serialize CcnxInterestHeader to Buffer::Iterator |
| 47 | * @param start Buffer to store serialized CcnxInterestHeader |
| 48 | * @param interest Pointer to CcnxInterestHeader to be serialized |
| 49 | * @return length of serialized CcnxInterestHeader |
| 50 | */ |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 51 | static size_t |
| 52 | Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest); |
| 53 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 54 | /** |
| 55 | * \brief Compute the size of serialized CcnxInterestHeader |
| 56 | * @param interest Pointer to CcnxInterestHeader |
| 57 | * @return length |
| 58 | */ |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 59 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 60 | GetSerializedSize (const CcnxInterestHeader &interest); |
| 61 | |
| 62 | static size_t |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 63 | Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject); |
| 64 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 65 | static size_t |
| 66 | GetSerializedSize (const CcnxContentObjectHeader &contentObject); |
| 67 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 68 | private: |
| 69 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 70 | AppendBlockHeader (Buffer::Iterator &start, size_t value, CcnbParser::ccn_tt block_type); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 71 | |
| 72 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 73 | EstimateBlockHeader (size_t value); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 74 | |
| 75 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 76 | AppendNumber (Buffer::Iterator &start, uint32_t number); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 77 | |
| 78 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 79 | EstimateNumber (uint32_t number); |
| 80 | |
| 81 | static size_t |
| 82 | AppendCloser (Buffer::Iterator &start); |
| 83 | |
| 84 | static size_t |
| 85 | AppendNameComponents (Buffer::Iterator &start, const CcnxNameComponents &name); |
| 86 | |
| 87 | static size_t |
| 88 | EstimateNameComponents (const CcnxNameComponents &name); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Append a binary timestamp as a BLOB using the ccn binary |
| 92 | * Timestamp representation (12-bit fraction). |
| 93 | * |
| 94 | * @param start start iterator of the buffer to append to. |
| 95 | * @param time - Time object |
| 96 | * |
| 97 | * @returns written length |
| 98 | */ |
| 99 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 100 | AppendTimestampBlob (Buffer::Iterator &start, const Time &time); |
| 101 | |
| 102 | static size_t |
| 103 | EstimateTimestampBlob (const Time &time); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Append a tagged BLOB |
| 107 | * |
| 108 | * This is a ccnb-encoded element with containing the BLOB as content |
| 109 | * |
| 110 | * @param start start iterator of the buffer to append to. |
| 111 | * @param dtag is the element's dtab |
| 112 | * @param data points to the binary data |
| 113 | * @param size is the size of the data, in bytes |
| 114 | * |
| 115 | * @returns written length |
| 116 | */ |
| 117 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 118 | AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag, |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 119 | const uint8_t *data, size_t size); |
| 120 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 121 | static size_t |
| 122 | EstimateTaggedBlob (CcnbParser::ccn_dtag dtag, size_t size); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace ns3 |
| 126 | |
| 127 | #endif // _CCNX_ENCODING_HELPER_H_ |
| 128 | |