blob: 4065db0fbaddb721687f96d4be061f5d32eace2f [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompson3b3aabf2013-06-21 16:50:20 -07005 */
6
7#include <cstdlib>
8#include <sstream>
9#include <iostream>
Jeff Thompson25b4e612013-10-10 16:03:24 -070010#include <ndn-cpp/interest.hpp>
Jeff Thompson3b3aabf2013-06-21 16:50:20 -070011
12using namespace std;
13using namespace ndn;
14
Jeff Thompson10ad12a2013-09-24 16:19:11 -070015uint8_t Interest1[] = {
Jeff Thompson7afc98e2013-06-27 14:33:53 -0700160x01, 0xd2,
17 0xf2, 0xfa, 0x9d, 0x6e, 0x64, 0x6e, 0x00, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0x00,
Jeff Thompson06f824a2013-07-08 17:14:30 -070018 0x05, 0x9a, 0x9e, 0x31, 0x32, 0x33, 0x00,
Jeff Thompson7afc98e2013-06-27 14:33:53 -070019 0x05, 0xa2, 0x8e, 0x34, 0x00,
20 0x03, 0xe2,
21 0x02, 0x85, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
22 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
23 0x00,
Jeff Thompson22552902013-07-07 21:26:20 -070024 0x02, 0xda, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0xea, 0x00, 0x00,
Jeff Thompson22552902013-07-07 21:26:20 -070025 0x05, 0xaa, 0x8e, 0x31, 0x00,
26 0x02, 0xfa, 0x8e, 0x34, 0x00,
27 0x02, 0xd2, 0x8e, 0x32, 0x00,
28 0x03, 0x82, 0x9d, 0x01, 0xe0, 0x00, 0x00,
29 0x02, 0xca, 0xb5, 0x61, 0x62, 0x61, 0x62, 0x61, 0x62, 0x00,
300x00,
Jeff Thompson7afc98e2013-06-27 14:33:53 -0700311
32};
33
Jeff Thompson1656e6a2013-08-29 18:01:48 -070034static void dumpInterest(const Interest& interest)
Jeff Thompsonf9d4bfd2013-08-21 11:27:24 -070035{
36 cout << "name: " << interest.getName().to_uri() << endl;
37 cout << "minSuffixComponents: ";
38 if (interest.getMinSuffixComponents() >= 0)
39 cout << interest.getMinSuffixComponents() << endl;
40 else
41 cout << "<none>" << endl;
42 cout << "maxSuffixComponents: ";
43 if (interest.getMaxSuffixComponents() >= 0)
44 cout << interest.getMaxSuffixComponents() << endl;
45 else
46 cout << "<none>" << endl;
47 cout << "publisherPublicKeyDigest: "
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070048 << (interest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ? toHex(*interest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()) : "<none>") << endl;
Jeff Thompsonf9d4bfd2013-08-21 11:27:24 -070049 cout << "exclude: "
50 << (interest.getExclude().getEntryCount() > 0 ? interest.getExclude().toUri() : "<none>") << endl;
51 cout << "lifetimeMilliseconds: ";
52 if (interest.getInterestLifetimeMilliseconds() >= 0)
53 cout << interest.getInterestLifetimeMilliseconds() << endl;
54 else
55 cout << "<none>" << endl;
56 cout << "childSelector: ";
57 if (interest.getChildSelector() >= 0)
58 cout << interest.getChildSelector() << endl;
59 else
60 cout << "<none>" << endl;
61 cout << "answerOriginKind: ";
62 if (interest.getAnswerOriginKind() >= 0)
63 cout << interest.getAnswerOriginKind() << endl;
64 else
65 cout << "<none>" << endl;
66 cout << "scope: ";
67 if (interest.getScope() >= 0)
68 cout << interest.getScope() << endl;
69 else
70 cout << "<none>" << endl;
71 cout << "nonce: "
Jeff Thompson412226d2013-09-12 15:55:46 -070072 << (interest.getNonce().size() > 0 ? toHex(*interest.getNonce()) : "<none>") << endl;
Jeff Thompsonf9d4bfd2013-08-21 11:27:24 -070073}
74
Jeff Thompson7afc98e2013-06-27 14:33:53 -070075int main(int argc, char** argv)
76{
77 try {
Jeff Thompson22552902013-07-07 21:26:20 -070078 Interest interest;
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070079 interest.wireDecode(Interest1, sizeof(Interest1));
Jeff Thompsonf9d4bfd2013-08-21 11:27:24 -070080 cout << "Interest:" << endl;
81 dumpInterest(interest);
Jeff Thompson2fb4b1b2013-07-01 15:10:43 -070082
Jeff Thompsonc2b7b142013-09-12 15:29:04 -070083 Blob encoding = interest.wireEncode();
Jeff Thompsoned4f3732013-08-15 17:34:34 -070084 cout << endl << "Re-encoded interest " << toHex(*encoding) << endl;
Jeff Thompson0d567da2013-07-14 22:10:21 -070085
Jeff Thompson06f824a2013-07-08 17:14:30 -070086 Interest reDecodedInterest;
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070087 reDecodedInterest.wireDecode(*encoding);
Jeff Thompsonf9d4bfd2013-08-21 11:27:24 -070088 cout << "Re-decoded Interest:" << endl;
89 dumpInterest(reDecodedInterest);
Jeff Thompson1656e6a2013-08-29 18:01:48 -070090 } catch (exception& e) {
Jeff Thompson8b666002013-07-08 01:16:26 -070091 cout << "exception: " << e.what() << endl;
Jeff Thompson7afc98e2013-06-27 14:33:53 -070092 }
Jeff Thompson3b3aabf2013-06-21 16:50:20 -070093 return 0;
94}