NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
dtag.cc
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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #include "dtag.h"
22 
23 #include "base-attr.h"
24 #include "base-tag.h"
25 
26 NDN_NAMESPACE_BEGIN
27 
28 namespace wire {
29 namespace CcnbParser {
30 
31 Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
32 {
33  m_dtag = dtag;
34  // std::cout << m_dtag << ", position: " << Block::counter << "\n";
42  if (dtag == CCN_DTAG_Content)
43  {
44  Block::ParseBlock (start, true); // process length field and ignore it
45  return; // hack #1. Do not process nesting block for <Content>
46  }
47 
48  // parse attributes until first nested block reached
49  while (!start.IsEnd () && BufferIteratorPeekU8 (start)!=CCN_CLOSE)
50  {
51  Ptr<Block> block = Block::ParseBlock (start);
52  if (DynamicCast<BaseAttr> (block)!=0)
53  m_attrs.push_back (block);
54  else
55  {
56  m_nestedTags.push_back (block);
57  break;
58  }
59  }
60 
61  // parse the rest of nested blocks
62  while (!start.IsEnd () && BufferIteratorPeekU8 (start)!=CCN_CLOSE)
63  {
64  // hack #2. Stop processing nested blocks if last block was <Content>
65  if (m_dtag == CCN_DTAG_Data && // we are in <Data>
66  DynamicCast<Dtag> (m_nestedTags.back())!=0 && // last block is DTAG
67  DynamicCast<Dtag> (m_nestedTags.back())->m_dtag == CCN_DTAG_Content)
68  {
69  return;
70  }
71 
72  m_nestedTags.push_back (Block::ParseBlock (start));
73  }
74 
75  // hack #3. Stop processing when last tag was <Data>
76  if (m_dtag == CCN_DTAG_Data && // we are in <Data>
77  DynamicCast<Dtag> (m_nestedTags.back())!=0 && // last block is DTAG
78  DynamicCast<Dtag> (m_nestedTags.back())->m_dtag == CCN_DTAG_Content)
79  {
80  return;
81  }
82 
83  if (start.IsEnd ())
84  throw CcnbDecodingException ();
85 
86  start.ReadU8 (); // read CCN_CLOSE
87  // std::cout << "closer, position = " << Block::counter << "\n";
88  // Block::counter ++;
89 }
90 
91 } // namespace CcnbParser
92 } // namespace wire
93 
94 NDN_NAMESPACE_END
Exception thrown if there is a parsing error.
Definition: common.h:50