Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #include "../ccnb.h" |
| 23 | |
| 24 | #include "wire-ccnb.h" |
| 25 | |
| 26 | #include "ns3/log.h" |
| 27 | |
| 28 | #include "ccnb-parser/common.h" |
| 29 | #include "ccnb-parser/visitors/void-depth-first-visitor.h" |
| 30 | #include "ccnb-parser/visitors/name-visitor.h" |
| 31 | #include "ccnb-parser/visitors/non-negative-integer-visitor.h" |
| 32 | #include "ccnb-parser/visitors/timestamp-visitor.h" |
| 33 | #include "ccnb-parser/visitors/string-visitor.h" |
| 34 | #include "ccnb-parser/visitors/uint32t-blob-visitor.h" |
| 35 | #include "ccnb-parser/visitors/content-type-visitor.h" |
| 36 | |
| 37 | #include "ccnb-parser/syntax-tree/block.h" |
| 38 | #include "ccnb-parser/syntax-tree/dtag.h" |
| 39 | |
| 40 | #include <boost/foreach.hpp> |
| 41 | |
| 42 | NS_LOG_COMPONENT_DEFINE ("ndn.wire.Ccnb.Data"); |
| 43 | |
| 44 | NDN_NAMESPACE_BEGIN |
| 45 | |
| 46 | namespace wire { |
| 47 | namespace ccnb { |
| 48 | |
| 49 | // const std::string DefaultDigestAlgorithm = "2.16.840.1.101.3.4.2.1"; |
| 50 | |
| 51 | class DataTrailer : public Trailer |
| 52 | { |
| 53 | public: |
| 54 | DataTrailer () |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | static TypeId GetTypeId () |
| 59 | { |
| 60 | static TypeId tid = TypeId ("ns3::ndn::Data::Ccnb::Closer") |
| 61 | .SetGroupName ("Ndn") |
| 62 | .SetParent<Trailer> () |
| 63 | .AddConstructor<DataTrailer> () |
| 64 | ; |
| 65 | return tid; |
| 66 | } |
| 67 | |
| 68 | virtual TypeId GetInstanceTypeId (void) const |
| 69 | { |
| 70 | return GetTypeId (); |
| 71 | } |
| 72 | |
| 73 | virtual void Print (std::ostream &os) const |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | virtual uint32_t GetSerializedSize (void) const |
| 78 | { |
| 79 | return 2; |
| 80 | } |
| 81 | |
| 82 | virtual void Serialize (Buffer::Iterator end) const |
| 83 | { |
| 84 | Buffer::Iterator i = end; |
| 85 | i.Prev (2); // Trailer interface requires us to go backwards |
| 86 | |
| 87 | i.WriteU8 (0x00); // </Content> |
| 88 | i.WriteU8 (0x00); // </ContentObject> |
| 89 | } |
| 90 | |
| 91 | virtual uint32_t Deserialize (Buffer::Iterator end) |
| 92 | { |
| 93 | Buffer::Iterator i = end; |
| 94 | i.Prev (2); // Trailer interface requires us to go backwards |
| 95 | |
| 96 | uint8_t closing_tag_content = i.ReadU8 (); |
| 97 | NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)"); |
| 98 | |
| 99 | uint8_t closing_tag_content_object = i.ReadU8 (); |
| 100 | NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)"); |
| 101 | |
| 102 | return 2; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | NS_OBJECT_ENSURE_REGISTERED (Data); |
| 107 | NS_OBJECT_ENSURE_REGISTERED (DataTrailer); |
| 108 | |
| 109 | TypeId |
| 110 | Data::GetTypeId (void) |
| 111 | { |
| 112 | static TypeId tid = TypeId ("ns3::ndn::Data::Ccnb") |
| 113 | .SetGroupName ("Ndn") |
| 114 | .SetParent<Header> () |
| 115 | .AddConstructor<Data> () |
| 116 | ; |
| 117 | return tid; |
| 118 | } |
| 119 | |
| 120 | TypeId |
| 121 | Data::GetInstanceTypeId (void) const |
| 122 | { |
| 123 | return GetTypeId (); |
| 124 | } |
| 125 | |
| 126 | Data::Data () |
| 127 | : m_data (Create<ndn::ContentObject> ()) |
| 128 | { |
| 129 | } |
| 130 | |
| 131 | Data::Data (Ptr<ndn::ContentObject> data) |
| 132 | : m_data (data) |
| 133 | { |
| 134 | } |
| 135 | |
| 136 | Ptr<ndn::ContentObject> |
| 137 | Data::GetData () |
| 138 | { |
| 139 | return m_data; |
| 140 | } |
| 141 | |
| 142 | Ptr<Packet> |
| 143 | Data::ToWire (Ptr<const ndn::ContentObject> data) |
| 144 | { |
| 145 | static DataTrailer trailer; |
| 146 | |
| 147 | Ptr<const Packet> p = data->GetWire (); |
| 148 | if (!p) |
| 149 | { |
| 150 | Ptr<Packet> packet = Create<Packet> (*data->GetPayload ()); |
| 151 | Data wireEncoding (ConstCast<ndn::ContentObject> (data)); |
| 152 | packet->AddHeader (wireEncoding); |
| 153 | packet->AddTrailer (trailer); |
| 154 | data->SetWire (packet); |
| 155 | |
| 156 | p = packet; |
| 157 | } |
| 158 | |
| 159 | return p->Copy (); |
| 160 | } |
| 161 | |
| 162 | Ptr<ndn::ContentObject> |
| 163 | Data::FromWire (Ptr<Packet> packet) |
| 164 | { |
| 165 | static DataTrailer trailer; |
| 166 | |
| 167 | Ptr<ndn::ContentObject> data = Create<ndn::ContentObject> (); |
| 168 | data->SetWire (packet->Copy ()); |
| 169 | |
| 170 | Data wireEncoding (data); |
| 171 | packet->RemoveHeader (wireEncoding); |
| 172 | packet->RemoveTrailer (trailer); |
| 173 | |
| 174 | data->SetPayload (packet); |
| 175 | |
| 176 | return data; |
| 177 | } |
| 178 | |
| 179 | void |
| 180 | Data::Serialize (Buffer::Iterator start) const |
| 181 | { |
| 182 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_ContentObject, CcnbParser::CCN_DTAG); // <ContentObject> |
| 183 | |
| 184 | // fake signature |
| 185 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_Signature, CcnbParser::CCN_DTAG); // <Signature> |
| 186 | // Signature ::= √DigestAlgorithm? |
| 187 | // Witness? |
| 188 | // √SignatureBits |
| 189 | // if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm) |
| 190 | // { |
| 191 | // Ccnb::AppendString (start, CcnbParser::CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ()); |
| 192 | // } |
| 193 | Ccnb::AppendTaggedBlob (start, CcnbParser::CCN_DTAG_SignatureBits, m_data->GetSignature ()); // <SignatureBits /> |
| 194 | Ccnb::AppendCloser (start); // </Signature> |
| 195 | |
| 196 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_Name, CcnbParser::CCN_DTAG); // <Name> |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 197 | Ccnb::SerializeName (start, m_data->GetName()); // <Component>...</Component>... |
| 198 | Ccnb::AppendCloser (start); // </Name> |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 199 | |
| 200 | // fake signature |
| 201 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_SignedInfo, CcnbParser::CCN_DTAG); // <SignedInfo> |
| 202 | // SignedInfo ::= √PublisherPublicKeyDigest |
| 203 | // √Timestamp |
| 204 | // √Type? |
| 205 | // √FreshnessSeconds? |
| 206 | // FinalBlockID? |
| 207 | // KeyLocator? |
| 208 | // Ccnb::AppendTaggedBlob (start, CcnbParser::CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>... |
| 209 | // GetSignedInfo ().GetPublisherPublicKeyDigest ()); |
| 210 | |
| 211 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_Timestamp, CcnbParser::CCN_DTAG); // <Timestamp>... |
| 212 | Ccnb::AppendTimestampBlob (start, m_data->GetTimestamp ()); |
| 213 | Ccnb::AppendCloser (start); |
| 214 | |
| 215 | // if (GetSignedInfo ().GetContentType () != DATA) |
| 216 | // { |
| 217 | // uint8_t type[3]; |
| 218 | // type[0] = (GetSignedInfo ().GetContentType () >> 16) & 0xFF; |
| 219 | // type[1] = (GetSignedInfo ().GetContentType () >> 8 ) & 0xFF; |
| 220 | // type[2] = (GetSignedInfo ().GetContentType () ) & 0xFF; |
| 221 | |
| 222 | // Ccnb::AppendTaggedBlob (start, CCN_DTAG_Type, type, 3); |
| 223 | // } |
| 224 | if (m_data->GetFreshness () > Seconds(0)) |
| 225 | { |
| 226 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_FreshnessSeconds, CcnbParser::CCN_DTAG); |
| 227 | Ccnb::AppendNumber (start, m_data->GetFreshness ().ToInteger (Time::S)); |
| 228 | Ccnb::AppendCloser (start); |
| 229 | } |
| 230 | if (m_data->GetKeyLocator () != 0) |
| 231 | { |
| 232 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_KeyLocator, CcnbParser::CCN_DTAG); // <KeyLocator> |
| 233 | { |
| 234 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_KeyName, CcnbParser::CCN_DTAG); // <KeyName> |
| 235 | { |
| 236 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_Name, CcnbParser::CCN_DTAG); // <Name> |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 237 | Ccnb::SerializeName (start, *m_data->GetKeyLocator ()); // <Component>...</Component>... |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 238 | Ccnb::AppendCloser (start); // </Name> |
| 239 | } |
| 240 | Ccnb::AppendCloser (start); // </KeyName> |
| 241 | } |
| 242 | Ccnb::AppendCloser (start); // </KeyLocator> |
| 243 | } |
| 244 | |
| 245 | Ccnb::AppendCloser (start); // </SignedInfo> |
| 246 | |
| 247 | Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_Content, CcnbParser::CCN_DTAG); // <Content> |
| 248 | |
| 249 | // there are no closing tags !!! |
| 250 | // The closing tag is handled by ContentObjectTail |
| 251 | } |
| 252 | |
| 253 | uint32_t |
| 254 | Data::GetSerializedSize () const |
| 255 | { |
| 256 | size_t written = 0; |
| 257 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_ContentObject); // <ContentObject> |
| 258 | |
| 259 | // fake signature |
| 260 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_Signature); // <Signature> |
| 261 | // Signature ::= DigestAlgorithm? |
| 262 | // Witness? |
| 263 | // SignatureBits |
| 264 | // if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm) |
| 265 | // { |
| 266 | // written += Ccnb::EstimateString (CcnbParser::CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ()); |
| 267 | // } |
| 268 | written += Ccnb::EstimateTaggedBlob (CcnbParser::CCN_DTAG_SignatureBits, |
| 269 | sizeof (m_data->GetSignature ())); // <SignatureBits /> |
| 270 | written += 1; // </Signature> |
| 271 | |
| 272 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_Name); // <Name> |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 273 | written += Ccnb::SerializedSizeName (m_data->GetName ()); // <Component>...</Component>... |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 274 | written += 1; // </Name> |
| 275 | |
| 276 | // fake signature |
| 277 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_SignedInfo); // <SignedInfo> |
| 278 | // SignedInfo ::= √PublisherPublicKeyDigest |
| 279 | // √Timestamp |
| 280 | // √Type? |
| 281 | // √FreshnessSeconds? |
| 282 | // FinalBlockID? |
| 283 | // KeyLocator? |
| 284 | |
| 285 | // written += Ccnb::EstimateTaggedBlob (CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>... |
| 286 | // sizeof (GetSignedInfo ().GetPublisherPublicKeyDigest ())); |
| 287 | |
| 288 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_Timestamp); // <Timestamp>... |
| 289 | written += Ccnb::EstimateTimestampBlob (m_data->GetTimestamp ()); |
| 290 | written += 1; |
| 291 | |
| 292 | // if (GetSignedInfo ().GetContentType () != DATA) |
| 293 | // { |
| 294 | // written += Ccnb::EstimateTaggedBlob (CcnbParser::CCN_DTAG_Type, 3); |
| 295 | // } |
| 296 | if (m_data->GetFreshness () > Seconds(0)) |
| 297 | { |
| 298 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_FreshnessSeconds); |
| 299 | written += Ccnb::EstimateNumber (m_data->GetFreshness ().ToInteger (Time::S)); |
| 300 | written += 1; |
| 301 | } |
| 302 | |
| 303 | if (m_data->GetKeyLocator () != 0) |
| 304 | { |
| 305 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_KeyLocator); // <KeyLocator> |
| 306 | { |
| 307 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_KeyName); // <KeyName> |
| 308 | { |
| 309 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_Name); // <Name> |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 310 | written += Ccnb::SerializedSizeName (*m_data->GetKeyLocator ()); // <Component>...</Component>... |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 311 | written += 1; // </Name> |
| 312 | } |
| 313 | written += 1; // </KeyName> |
| 314 | } |
| 315 | written += 1; // </KeyLocator> |
| 316 | } |
| 317 | |
| 318 | written += 1; // </SignedInfo> |
| 319 | |
| 320 | written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_Content); // <Content> |
| 321 | |
| 322 | // there are no closing tags !!! |
| 323 | // The closing tag is handled by ContentObjectTail |
| 324 | return written; |
| 325 | } |
| 326 | |
| 327 | class ContentObjectVisitor : public CcnbParser::VoidDepthFirstVisitor |
| 328 | { |
| 329 | public: |
| 330 | virtual void visit (CcnbParser::Dtag &n, boost::any param/*should be ContentObject* */) |
| 331 | { |
| 332 | // uint32_t n.m_dtag; |
| 333 | // std::list< Ptr<CcnbParser::Block> > n.m_nestedBlocks; |
| 334 | static CcnbParser::NameVisitor nameVisitor; |
| 335 | static CcnbParser::NonNegativeIntegerVisitor nonNegativeIntegerVisitor; |
| 336 | static CcnbParser::TimestampVisitor timestampVisitor; |
| 337 | static CcnbParser::StringVisitor stringVisitor; |
| 338 | static CcnbParser::Uint32tBlobVisitor uint32tBlobVisitor; |
| 339 | static CcnbParser::ContentTypeVisitor contentTypeVisitor; |
| 340 | |
| 341 | ndn::ContentObject &contentObject = *(boost::any_cast<ndn::ContentObject*> (param)); |
| 342 | |
| 343 | switch (n.m_dtag) |
| 344 | { |
| 345 | case CcnbParser::CCN_DTAG_ContentObject: |
| 346 | // process nested blocks |
| 347 | BOOST_FOREACH (Ptr<CcnbParser::Block> block, n.m_nestedTags) |
| 348 | { |
| 349 | block->accept (*this, param); |
| 350 | } |
| 351 | break; |
| 352 | case CcnbParser::CCN_DTAG_Name: |
| 353 | { |
| 354 | // process name components |
| 355 | Ptr<Name> name = Create<Name> (); |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 356 | n.accept (nameVisitor, GetPointer (name)); |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 357 | contentObject.SetName (name); |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | case CcnbParser::CCN_DTAG_Signature: |
| 362 | // process nested blocks |
| 363 | BOOST_FOREACH (Ptr<CcnbParser::Block> block, n.m_nestedTags) |
| 364 | { |
| 365 | block->accept (*this, param); |
| 366 | } |
| 367 | break; |
| 368 | |
| 369 | // case CCN_DTAG_DigestAlgorithm: |
| 370 | // NS_LOG_DEBUG ("DigestAlgorithm"); |
| 371 | // if (n.m_nestedTags.size ()!=1) // should be exactly one UDATA inside this tag |
| 372 | // throw CcnbParser::CcnbDecodingException (); |
| 373 | |
| 374 | // contentObject.GetSignature ().SetDigestAlgorithm |
| 375 | // (boost::any_cast<std::string> ((*n.m_nestedTags.begin())->accept |
| 376 | // (stringVisitor))); |
| 377 | // break; |
| 378 | |
| 379 | case CcnbParser::CCN_DTAG_SignatureBits: |
| 380 | NS_LOG_DEBUG ("SignatureBits"); |
| 381 | if (n.m_nestedTags.size ()!=1) // should be only one nested tag |
| 382 | throw CcnbParser::CcnbDecodingException (); |
| 383 | |
| 384 | contentObject.SetSignature |
| 385 | (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 386 | (uint32tBlobVisitor))); |
| 387 | break; |
| 388 | |
| 389 | case CcnbParser::CCN_DTAG_SignedInfo: |
| 390 | // process nested blocks |
| 391 | BOOST_FOREACH (Ptr<CcnbParser::Block> block, n.m_nestedTags) |
| 392 | { |
| 393 | block->accept (*this, param); |
| 394 | } |
| 395 | break; |
| 396 | |
| 397 | // case CCN_DTAG_PublisherPublicKeyDigest: |
| 398 | // NS_LOG_DEBUG ("PublisherPublicKeyDigest"); |
| 399 | // if (n.m_nestedTags.size ()!=1) // should be only one nested tag |
| 400 | // throw CcnbParser::CcnbDecodingException (); |
| 401 | |
| 402 | // contentObject.GetSignedInfo ().SetPublisherPublicKeyDigest |
| 403 | // (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 404 | // (uint32tBlobVisitor))); |
| 405 | // break; |
| 406 | |
| 407 | case CcnbParser::CCN_DTAG_Timestamp: |
| 408 | NS_LOG_DEBUG ("Timestamp"); |
| 409 | if (n.m_nestedTags.size()!=1) // should be exactly one nested tag |
| 410 | throw CcnbParser::CcnbDecodingException (); |
| 411 | |
| 412 | contentObject.SetTimestamp |
| 413 | (boost::any_cast<Time> ((*n.m_nestedTags.begin())->accept |
| 414 | (timestampVisitor))); |
| 415 | break; |
| 416 | |
| 417 | // case CCN_DTAG_Type: |
| 418 | // NS_LOG_DEBUG ("Type"); |
| 419 | // if (n.m_nestedTags.size ()!=1) // should be only one nested tag |
| 420 | // throw CcnbParser::CcnbDecodingException (); |
| 421 | |
| 422 | // contentObject.GetSignedInfo ().SetContentType |
| 423 | // (static_cast<Data::ContentType> |
| 424 | // (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 425 | // (contentTypeVisitor)))); |
| 426 | // break; |
| 427 | |
| 428 | case CcnbParser::CCN_DTAG_FreshnessSeconds: |
| 429 | NS_LOG_DEBUG ("FreshnessSeconds"); |
| 430 | |
| 431 | if (n.m_nestedTags.size()!=1) // should be exactly one nested tag |
| 432 | throw CcnbParser::CcnbDecodingException (); |
| 433 | |
| 434 | contentObject.SetFreshness |
| 435 | (Seconds |
| 436 | (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 437 | (nonNegativeIntegerVisitor)))); |
| 438 | break; |
| 439 | |
| 440 | case CcnbParser::CCN_DTAG_KeyLocator: |
| 441 | // process nested blocks |
| 442 | BOOST_FOREACH (Ptr<CcnbParser::Block> block, n.m_nestedTags) |
| 443 | { |
| 444 | block->accept (*this, param); |
| 445 | } |
| 446 | break; |
| 447 | |
| 448 | case CcnbParser::CCN_DTAG_KeyName: |
| 449 | { |
| 450 | if (n.m_nestedTags.size ()!=1) // should be exactly one nested tag |
| 451 | throw CcnbParser::CcnbDecodingException (); |
| 452 | |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 453 | // process name components |
| 454 | Ptr<Name> name = Create<Name> (); |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 455 | n.accept (nameVisitor, GetPointer (name)); |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 456 | contentObject.SetKeyLocator (name); |
| 457 | break; |
| 458 | } |
| 459 | |
| 460 | case CcnbParser::CCN_DTAG_Content: // !!! HACK |
| 461 | // This hack was necessary for memory optimizations (i.e., content is virtual payload) |
| 462 | NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag"); |
| 463 | break; |
| 464 | |
| 465 | default: // ignore all other stuff |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | }; |
| 470 | |
| 471 | uint32_t |
| 472 | Data::Deserialize (Buffer::Iterator start) |
| 473 | { |
| 474 | static ContentObjectVisitor contentObjectVisitor; |
| 475 | |
| 476 | Buffer::Iterator i = start; |
| 477 | Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i); |
| 478 | root->accept (contentObjectVisitor, GetPointer (m_data)); |
| 479 | |
| 480 | return i.GetDistanceFrom (start); |
| 481 | } |
| 482 | |
| 483 | void |
| 484 | Data::Print (std::ostream &os) const |
| 485 | { |
| 486 | os << "D: " << m_data->GetName (); |
| 487 | // os << "<ContentObject><Name>" << GetName () << "</Name><Content>"; |
| 488 | } |
| 489 | |
| 490 | } // ccnb |
| 491 | } // wire |
| 492 | |
| 493 | NDN_NAMESPACE_END |