blob: dcaadaf3ee9712a73e31650c853545385a89e135 [file] [log] [blame]
Alexander Afanasyev8b379052011-08-21 16:58:20 -07001/* -*- 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#ifndef _CCNB_PARSER_BLOCK_H_
22#define _CCNB_PARSER_BLOCK_H_
23
24#include "ns3/simple-ref-count.h"
25#include "ns3/buffer.h"
26#include "ns3/ptr.h"
27
28// visitors
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070029#include "../visitors/void-no-argu-visitor.h"
30#include "../visitors/void-visitor.h"
31#include "../visitors/no-argu-visitor.h"
32#include "../visitors/visitor.h"
Alexander Afanasyev8b379052011-08-21 16:58:20 -070033
Alexander Afanasyev1043c702013-07-15 16:21:09 -070034NDN_NAMESPACE_BEGIN
35
36namespace wire {
Alexander Afanasyev8b379052011-08-21 16:58:20 -070037namespace CcnbParser {
38
39/**
40 * \ingroup ccnx-ccnb
41 * \brief Base class for ccnb-encoded node
42 *
43 * This class provides a static method to create a new block
44 * (recursively) from the stream
45 *
46 * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
47 */
48class Block : public SimpleRefCount<Block>
49{
50public:
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070051 // static int counter;
Alexander Afanasyev8b379052011-08-21 16:58:20 -070052 /**
53 * \brief Parsing stream (recursively) and creating a parsed BLOCK
54 * object
55 *
Alexander Afanasyevb4bf3ef2013-07-30 10:40:55 -070056 * \param start buffer iterator pointing to the start position for parsing
57 * \param dontParseBlock parameter to indicate whether the block should not be parsed, just length
58 * of the block should be consumed (e.g., in case of "cheating" with content of Data packets)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070059 * \returns parsed ccnb-encoded block, that could contain more block inside
60 */
61 static Ptr<Block>
Alexander Afanasyevb4bf3ef2013-07-30 10:40:55 -070062 ParseBlock (Buffer::Iterator &start, bool dontParseBlock = false);
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080063
64 virtual ~Block ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070065
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070066 virtual void accept( VoidNoArguVisitor &v ) = 0; ///< @brief Accept visitor void(*)()
67 virtual void accept( VoidVisitor &v, boost::any param ) = 0; ///< @brief Accept visitor void(*)(boost::any)
68 virtual boost::any accept( NoArguVisitor &v ) = 0; ///< @brief Accept visitor boost::any(*)()
69 virtual boost::any accept( Visitor &v, boost::any param ) = 0; ///< @brief Accept visitor boost::any(*)(boost::any)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070070};
71
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070072/**
73 * @brief Necessary until Buffer::Iterator gets PeekU8 call
74 * @param i buffer iterator
75 * @return peeked uint8_t value
76 */
Alexander Afanasyevc1e33eb2012-05-31 12:13:17 -070077inline
78uint8_t
79BufferIteratorPeekU8 (Buffer::Iterator &i)
80{
81 uint8_t ret = i.ReadU8 ();
82 i.Prev ();
83 return ret;
84}
85
Alexander Afanasyev1043c702013-07-15 16:21:09 -070086} // namespace CcnbParser
87} // namespace wire
88
89NDN_NAMESPACE_END
Alexander Afanasyev8b379052011-08-21 16:58:20 -070090
91#endif // _CCNB_PARSER_BLOCK_H_