blob: 90fad22ea29fe08dcf0ddb363f07eeb82dfd83a8 [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
26#include "ns3/ccnx.h"
27#include "ns3/ptr.h"
28#include "ns3/nstime.h"
29#include "ns3/buffer.h"
30
31namespace ns3 {
32
33namespace Name{ class Components; }
34
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
49 Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
50
51private:
52 static size_t
53 AppendBlockHeader (Buffer::Iterator start, size_t value, Ccnx::ccn_tt block_type);
54
55 static size_t
56 AppendNumber (Buffer::Iterator start, uint32_t number);
57
58 static size_t
59 AppendCloser (Buffer::Iterator start);
60
61 static size_t
62 AppendNameComponents (Buffer::Iterator start, const Name::Components &name);
63
64 /**
65 * Append a binary timestamp as a BLOB using the ccn binary
66 * Timestamp representation (12-bit fraction).
67 *
68 * @param start start iterator of the buffer to append to.
69 * @param time - Time object
70 *
71 * @returns written length
72 */
73 static size_t
74 AppendTimestampBlob (Buffer::Iterator start, Time time);
75
76 /**
77 * Append a tagged BLOB
78 *
79 * This is a ccnb-encoded element with containing the BLOB as content
80 *
81 * @param start start iterator of the buffer to append to.
82 * @param dtag is the element's dtab
83 * @param data points to the binary data
84 * @param size is the size of the data, in bytes
85 *
86 * @returns written length
87 */
88 static size_t
89 AppendTaggedBlob (Buffer::Iterator start, Ccnx::ccn_dtag dtag,
90 const uint8_t *data, size_t size);
91
92};
93
94} // namespace ns3
95
96#endif // _CCNX_ENCODING_HELPER_H_
97