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 | * |
| 18 | * Author: |
| 19 | */ |
| 20 | |
| 21 | #ifndef _CCNX_ENCODING_HELPER_H_ |
| 22 | #define _CCNX_ENCODING_HELPER_H_ |
| 23 | |
| 24 | #include <sys/types.h> |
| 25 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 26 | #include "ns3/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 | /** |
| 39 | * Helper to encode/decode ccnb formatted CCNx message |
| 40 | * |
| 41 | */ |
| 42 | class CcnxEncodingHelper |
| 43 | { |
| 44 | public: |
| 45 | static size_t |
| 46 | Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest); |
| 47 | |
| 48 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 49 | GetSerializedSize (const CcnxInterestHeader &interest); |
| 50 | |
| 51 | static size_t |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 52 | Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject); |
| 53 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 54 | static size_t |
| 55 | GetSerializedSize (const CcnxContentObjectHeader &contentObject); |
| 56 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 57 | private: |
| 58 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 59 | AppendBlockHeader (Buffer::Iterator &start, size_t value, CcnbParser::ccn_tt block_type); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 60 | |
| 61 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 62 | EstimateBlockHeader (size_t value); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 63 | |
| 64 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 65 | AppendNumber (Buffer::Iterator &start, uint32_t number); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 66 | |
| 67 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 68 | EstimateNumber (uint32_t number); |
| 69 | |
| 70 | static size_t |
| 71 | AppendCloser (Buffer::Iterator &start); |
| 72 | |
| 73 | static size_t |
| 74 | AppendNameComponents (Buffer::Iterator &start, const CcnxNameComponents &name); |
| 75 | |
| 76 | static size_t |
| 77 | EstimateNameComponents (const CcnxNameComponents &name); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Append a binary timestamp as a BLOB using the ccn binary |
| 81 | * Timestamp representation (12-bit fraction). |
| 82 | * |
| 83 | * @param start start iterator of the buffer to append to. |
| 84 | * @param time - Time object |
| 85 | * |
| 86 | * @returns written length |
| 87 | */ |
| 88 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 89 | AppendTimestampBlob (Buffer::Iterator &start, const Time &time); |
| 90 | |
| 91 | static size_t |
| 92 | EstimateTimestampBlob (const Time &time); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Append a tagged BLOB |
| 96 | * |
| 97 | * This is a ccnb-encoded element with containing the BLOB as content |
| 98 | * |
| 99 | * @param start start iterator of the buffer to append to. |
| 100 | * @param dtag is the element's dtab |
| 101 | * @param data points to the binary data |
| 102 | * @param size is the size of the data, in bytes |
| 103 | * |
| 104 | * @returns written length |
| 105 | */ |
| 106 | static size_t |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 107 | AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag, |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 108 | const uint8_t *data, size_t size); |
| 109 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 110 | static size_t |
| 111 | EstimateTaggedBlob (CcnbParser::ccn_dtag dtag, size_t size); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace ns3 |
| 115 | |
| 116 | #endif // _CCNX_ENCODING_HELPER_H_ |
| 117 | |