blob: acce9224c4795a77481e12b32137ea40959c6945 [file] [log] [blame]
Alexander Afanasyev834f35c2011-08-16 17:13:50 -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:
19 */
20
21#ifndef _CCNX_ENCODING_HELPER_H_
22#define _CCNX_ENCODING_HELPER_H_
23
24#include <sys/types.h>
25
Alexander Afanasyevf9f4eb02011-12-16 01:51:14 -080026#include "ccnb-parser/ccnb-parser-common.h"
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070027#include "ns3/ptr.h"
28#include "ns3/nstime.h"
29#include "ns3/buffer.h"
30
31namespace ns3 {
32
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070033class CcnxNameComponents;
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070034
35class CcnxInterestHeader;
36class CcnxContentObjectHeader;
37
38/**
39 * Helper to encode/decode ccnb formatted CCNx message
40 *
41 */
42class CcnxEncodingHelper
43{
44public:
45 static size_t
46 Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest);
47
48 static size_t
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070049 GetSerializedSize (const CcnxInterestHeader &interest);
50
51 static size_t
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070052 Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
53
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070054 static size_t
55 GetSerializedSize (const CcnxContentObjectHeader &contentObject);
56
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070057private:
58 static size_t
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070059 AppendBlockHeader (Buffer::Iterator &start, size_t value, CcnbParser::ccn_tt block_type);
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070060
61 static size_t
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070062 EstimateBlockHeader (size_t value);
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070063
64 static size_t
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070065 AppendNumber (Buffer::Iterator &start, uint32_t number);
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070066
67 static size_t
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070068 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 Afanasyev834f35c2011-08-16 17:13:50 -070078
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 Afanasyev85a3bca2011-08-31 16:51:03 -070089 AppendTimestampBlob (Buffer::Iterator &start, const Time &time);
90
91 static size_t
92 EstimateTimestampBlob (const Time &time);
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070093
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 Afanasyev85a3bca2011-08-31 16:51:03 -0700107 AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag,
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700108 const uint8_t *data, size_t size);
109
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700110 static size_t
111 EstimateTaggedBlob (CcnbParser::ccn_dtag dtag, size_t size);
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700112};
113
114} // namespace ns3
115
116#endif // _CCNX_ENCODING_HELPER_H_
117