Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -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 | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #include "ndn-encoding-helper.h" |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 23 | #include "ns3/ndn-name-components.h" |
| 24 | #include "ns3/ndn-interest-header.h" |
| 25 | #include "ns3/ndn-content-object-header.h" |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 26 | |
| 27 | #include <sstream> |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 28 | #include <boost/foreach.hpp> |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ns3 { |
| 31 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 32 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 33 | NdnEncodingHelper::Serialize (Buffer::Iterator start, const NdnInterestHeader &interest) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 34 | { |
| 35 | size_t written = 0; |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 36 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Interest, CcnbParser::CCN_DTAG); // <Interest> |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 38 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Name, CcnbParser::CCN_DTAG); // <Name> |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 39 | written += AppendNameComponents (start, interest.GetName()); // <Component>...</Component>... |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 40 | written += AppendCloser (start); // </Name> |
| 41 | |
| 42 | if (interest.GetMinSuffixComponents() >= 0) |
| 43 | { |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 44 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_MinSuffixComponents, CcnbParser::CCN_DTAG); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 45 | written += AppendNumber (start, interest.GetMinSuffixComponents ()); |
| 46 | written += AppendCloser (start); |
| 47 | } |
| 48 | if (interest.GetMaxSuffixComponents() >= 0) |
| 49 | { |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 50 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_MaxSuffixComponents, CcnbParser::CCN_DTAG); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 51 | written += AppendNumber (start, interest.GetMaxSuffixComponents ()); |
| 52 | written += AppendCloser (start); |
| 53 | } |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 54 | if (interest.IsEnabledExclude() && interest.GetExclude().size() > 0) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 55 | { |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 56 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Exclude, CcnbParser::CCN_DTAG); // <Exclude> |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 57 | written += AppendNameComponents (start, interest.GetExclude()); // <Component>...</Component>... |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 58 | written += AppendCloser (start); // </Exclude> |
| 59 | } |
| 60 | if (interest.IsEnabledChildSelector()) |
| 61 | { |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 62 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_ChildSelector, CcnbParser::CCN_DTAG); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 63 | written += AppendNumber (start, 1); |
| 64 | written += AppendCloser (start); |
| 65 | } |
| 66 | if (interest.IsEnabledAnswerOriginKind()) |
| 67 | { |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 68 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_AnswerOriginKind, CcnbParser::CCN_DTAG); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 69 | written += AppendNumber (start, 1); |
| 70 | written += AppendCloser (start); |
| 71 | } |
| 72 | if (interest.GetScope() >= 0) |
| 73 | { |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 74 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Scope, CcnbParser::CCN_DTAG); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 75 | written += AppendNumber (start, interest.GetScope ()); |
| 76 | written += AppendCloser (start); |
| 77 | } |
| 78 | if (!interest.GetInterestLifetime().IsZero()) |
| 79 | { |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 80 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_InterestLifetime, CcnbParser::CCN_DTAG); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 81 | written += AppendTimestampBlob (start, interest.GetInterestLifetime ()); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 82 | written += AppendCloser (start); |
| 83 | } |
| 84 | if (interest.GetNonce()>0) |
| 85 | { |
| 86 | uint32_t nonce = interest.GetNonce(); |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 87 | written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Nonce, nonce); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 88 | } |
Ilya Moiseenko | d1f1951 | 2011-11-16 14:31:19 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 90 | if (interest.GetNack ()>0) |
Ilya Moiseenko | d1f1951 | 2011-11-16 14:31:19 -0800 | [diff] [blame] | 91 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 92 | written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Nack, CcnbParser::CCN_DTAG); |
| 93 | written += AppendNumber (start, interest.GetNack ()); |
Ilya Moiseenko | d1f1951 | 2011-11-16 14:31:19 -0800 | [diff] [blame] | 94 | written += AppendCloser (start); |
| 95 | } |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 96 | written += AppendCloser (start); // </Interest> |
| 97 | |
| 98 | return written; |
| 99 | } |
| 100 | |
| 101 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 102 | NdnEncodingHelper::GetSerializedSize (const NdnInterestHeader &interest) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 103 | { |
| 104 | size_t written = 0; |
| 105 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Interest); // <Interest> |
| 106 | |
| 107 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Name); // <Name> |
| 108 | written += EstimateNameComponents (interest.GetName()); // <Component>...</Component>... |
| 109 | written += 1; // </Name> |
| 110 | |
| 111 | if (interest.GetMinSuffixComponents() >= 0) |
| 112 | { |
| 113 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_MinSuffixComponents); |
| 114 | written += EstimateNumber (interest.GetMinSuffixComponents ()); |
| 115 | written += 1; |
| 116 | } |
| 117 | if (interest.GetMaxSuffixComponents() >= 0) |
| 118 | { |
| 119 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_MaxSuffixComponents); |
| 120 | written += EstimateNumber (interest.GetMaxSuffixComponents ()); |
| 121 | written += 1; |
| 122 | } |
| 123 | if (interest.IsEnabledExclude() && interest.GetExclude().size() > 0) |
| 124 | { |
| 125 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Exclude); |
| 126 | written += EstimateNameComponents (interest.GetExclude()); // <Component>...</Component>... |
| 127 | written += 1; // </Exclude> |
| 128 | } |
| 129 | if (interest.IsEnabledChildSelector()) |
| 130 | { |
| 131 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_ChildSelector); |
| 132 | written += EstimateNumber (1); |
| 133 | written += 1; |
| 134 | } |
| 135 | if (interest.IsEnabledAnswerOriginKind()) |
| 136 | { |
| 137 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_AnswerOriginKind); |
| 138 | written += EstimateNumber (1); |
| 139 | written += 1; |
| 140 | } |
| 141 | if (interest.GetScope() >= 0) |
| 142 | { |
| 143 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Scope); |
| 144 | written += EstimateNumber (interest.GetScope ()); |
| 145 | written += 1; |
| 146 | } |
| 147 | if (!interest.GetInterestLifetime().IsZero()) |
| 148 | { |
| 149 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_InterestLifetime); |
| 150 | written += EstimateTimestampBlob (interest.GetInterestLifetime()); |
| 151 | written += 1; |
| 152 | } |
| 153 | if (interest.GetNonce()>0) |
| 154 | { |
| 155 | written += EstimateTaggedBlob (CcnbParser::CCN_DTAG_Nonce, sizeof(uint32_t)); |
| 156 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 157 | if (interest.GetNack ()>0) |
Ilya Moiseenko | aa17c8e | 2011-10-28 13:04:30 -0700 | [diff] [blame] | 158 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 159 | written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Nack); |
| 160 | written += EstimateNumber (interest.GetNack ()); |
Ilya Moiseenko | aa17c8e | 2011-10-28 13:04:30 -0700 | [diff] [blame] | 161 | written += 1; |
| 162 | } |
| 163 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 164 | written += 1; // </Interest> |
| 165 | |
| 166 | return written; |
| 167 | } |
| 168 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 169 | ////////////////////////////////////////////////////////////////////// |
| 170 | ////////////////////////////////////////////////////////////////////// |
| 171 | ////////////////////////////////////////////////////////////////////// |
| 172 | |
| 173 | #define CCN_TT_BITS 3 |
| 174 | #define CCN_TT_MASK ((1 << CCN_TT_BITS) - 1) |
| 175 | #define CCN_MAX_TINY ((1 << (7-CCN_TT_BITS)) - 1) |
| 176 | #define CCN_TT_HBIT ((unsigned char)(1 << 7)) |
| 177 | |
| 178 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 179 | NdnEncodingHelper::AppendBlockHeader (Buffer::Iterator &start, size_t val, CcnbParser::ccn_tt tt) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 180 | { |
| 181 | unsigned char buf[1+8*((sizeof(val)+6)/7)]; |
| 182 | unsigned char *p = &(buf[sizeof(buf)-1]); |
| 183 | size_t n = 1; |
| 184 | p[0] = (CCN_TT_HBIT & ~CcnbParser::CCN_CLOSE) | |
| 185 | ((val & CCN_MAX_TINY) << CCN_TT_BITS) | |
| 186 | (CCN_TT_MASK & tt); |
| 187 | val >>= (7-CCN_TT_BITS); |
| 188 | while (val != 0) { |
| 189 | (--p)[0] = (((unsigned char)val) & ~CCN_TT_HBIT) | CcnbParser::CCN_CLOSE; |
| 190 | n++; |
| 191 | val >>= 7; |
| 192 | } |
| 193 | start.Write (p,n); |
| 194 | return n; |
| 195 | } |
| 196 | |
| 197 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 198 | NdnEncodingHelper::EstimateBlockHeader (size_t value) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 199 | { |
| 200 | value >>= (7-CCN_TT_BITS); |
| 201 | size_t n = 1; |
| 202 | while (value>0) |
| 203 | { |
| 204 | value >>= 7; |
| 205 | n++; |
| 206 | } |
| 207 | return n; |
| 208 | } |
| 209 | |
| 210 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 211 | NdnEncodingHelper::AppendNumber (Buffer::Iterator &start, uint32_t number) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 212 | { |
| 213 | std::ostringstream os; |
| 214 | os << number; |
| 215 | |
| 216 | size_t written = 0; |
| 217 | written += AppendBlockHeader (start, os.str().size(), CcnbParser::CCN_UDATA); |
| 218 | written += os.str().size(); |
| 219 | start.Write (reinterpret_cast<const unsigned char*>(os.str().c_str()), os.str().size()); |
| 220 | |
| 221 | return written; |
| 222 | } |
| 223 | |
| 224 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 225 | NdnEncodingHelper::EstimateNumber (uint32_t number) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 226 | { |
| 227 | std::ostringstream os; |
| 228 | os << number; |
| 229 | return EstimateBlockHeader (os.str ().size ()) + os.str ().size (); |
| 230 | } |
| 231 | |
| 232 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 233 | NdnEncodingHelper::AppendCloser (Buffer::Iterator &start) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 234 | { |
| 235 | start.WriteU8 (CcnbParser::CCN_CLOSE); |
| 236 | return 1; |
| 237 | } |
| 238 | |
| 239 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 240 | NdnEncodingHelper::AppendNameComponents (Buffer::Iterator &start, const NdnNameComponents &name) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 241 | { |
| 242 | size_t written = 0; |
| 243 | BOOST_FOREACH (const std::string &component, name.GetComponents()) |
| 244 | { |
| 245 | written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Component, |
| 246 | reinterpret_cast<const uint8_t*>(component.c_str()), component.size()); |
| 247 | } |
| 248 | return written; |
| 249 | } |
| 250 | |
| 251 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 252 | NdnEncodingHelper::EstimateNameComponents (const NdnNameComponents &name) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 253 | { |
| 254 | size_t written = 0; |
| 255 | BOOST_FOREACH (const std::string &component, name.GetComponents()) |
| 256 | { |
| 257 | written += EstimateTaggedBlob (CcnbParser::CCN_DTAG_Component, component.size()); |
| 258 | } |
| 259 | return written; |
| 260 | } |
| 261 | |
| 262 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 263 | NdnEncodingHelper::AppendTimestampBlob (Buffer::Iterator &start, const Time &time) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 264 | { |
| 265 | // the original function implements Markers... thought not sure what are these markers for... |
| 266 | |
| 267 | // Determine miminal number of bytes required to store the timestamp |
| 268 | int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough |
| 269 | intmax_t ts = time.ToInteger (Time::S) >> 4; |
| 270 | for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes? |
| 271 | required_bytes++; |
| 272 | |
| 273 | size_t len = AppendBlockHeader(start, required_bytes, CcnbParser::CCN_BLOB); |
| 274 | |
| 275 | // write part with seconds |
| 276 | ts = time.ToInteger (Time::S) >> 4; |
| 277 | for (int i = 0; i < required_bytes - 2; i++) |
| 278 | start.WriteU8 ( ts >> (8 * (required_bytes - 3 - i)) ); |
| 279 | |
| 280 | /* arithmetic contortions are to avoid overflowing 31 bits */ |
| 281 | ts = ((time.ToInteger (Time::S) & 15) << 12) + |
| 282 | (((time.ToInteger (Time::NS) % 1000000000) / 5 * 8 + 195312) / 390625); |
| 283 | for (int i = required_bytes - 2; i < required_bytes; i++) |
| 284 | start.WriteU8 ( ts >> (8 * (required_bytes - 1 - i)) ); |
| 285 | |
| 286 | return len + required_bytes; |
| 287 | } |
| 288 | |
| 289 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 290 | NdnEncodingHelper::EstimateTimestampBlob (const Time &time) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 291 | { |
| 292 | int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough |
| 293 | intmax_t ts = time.ToInteger (Time::S) >> 4; |
| 294 | for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes? |
| 295 | required_bytes++; |
| 296 | |
| 297 | return EstimateBlockHeader (required_bytes) + required_bytes; |
| 298 | } |
| 299 | |
| 300 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 301 | NdnEncodingHelper::AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag, |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 302 | const uint8_t *data, size_t size) |
| 303 | { |
| 304 | size_t written = AppendBlockHeader (start, dtag, CcnbParser::CCN_DTAG); |
| 305 | /* 2 */ |
| 306 | if (size>0) |
| 307 | { |
| 308 | written += AppendBlockHeader (start, size, CcnbParser::CCN_BLOB); |
| 309 | start.Write (data, size); |
| 310 | written += size; |
| 311 | /* size */ |
| 312 | } |
| 313 | written += AppendCloser (start); |
| 314 | /* 1 */ |
| 315 | |
| 316 | return written; |
| 317 | } |
| 318 | |
| 319 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 320 | NdnEncodingHelper::EstimateTaggedBlob (CcnbParser::ccn_dtag dtag, size_t size) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 321 | { |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 322 | if (size>0) |
| 323 | return EstimateBlockHeader (dtag) + EstimateBlockHeader (size) + size + 1; |
| 324 | else |
| 325 | return EstimateBlockHeader (dtag) + 1; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 328 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 329 | NdnEncodingHelper::AppendString (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag, |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 330 | const std::string &string) |
| 331 | { |
| 332 | size_t written = AppendBlockHeader (start, dtag, CcnbParser::CCN_DTAG); |
| 333 | { |
| 334 | written += AppendBlockHeader (start, string.size (), CcnbParser::CCN_UDATA); |
| 335 | start.Write (reinterpret_cast<const uint8_t*> (string.c_str ()), string.size ()); |
| 336 | written += string.size (); |
| 337 | } |
| 338 | written += AppendCloser (start); |
| 339 | |
| 340 | return written; |
| 341 | } |
| 342 | |
| 343 | size_t |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 344 | NdnEncodingHelper::EstimateString (CcnbParser::ccn_dtag dtag, const std::string &string) |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 345 | { |
| 346 | return EstimateBlockHeader (dtag) + EstimateBlockHeader (string.size ()) + string.size () + 1; |
| 347 | } |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 348 | |
| 349 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 350 | } // namespace ns3 |