Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 3b3aabf | 2013-06-21 16:50:20 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <cstdlib> |
| 7 | #include <sstream> |
| 8 | #include <iostream> |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 9 | #include <ndn-cpp/interest.hpp> |
Jeff Thompson | 3b3aabf | 2013-06-21 16:50:20 -0700 | [diff] [blame] | 10 | |
| 11 | using namespace std; |
| 12 | using namespace ndn; |
| 13 | |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 14 | unsigned char Interest1[] = { |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 15 | 0x01, 0xd2, |
| 16 | 0xf2, 0xfa, 0x9d, 0x6e, 0x64, 0x6e, 0x00, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0x00, |
Jeff Thompson | 06f824a | 2013-07-08 17:14:30 -0700 | [diff] [blame] | 17 | 0x05, 0x9a, 0x9e, 0x31, 0x32, 0x33, 0x00, |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 18 | 0x05, 0xa2, 0x8e, 0x34, 0x00, |
| 19 | 0x03, 0xe2, |
| 20 | 0x02, 0x85, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 21 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 22 | 0x00, |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 23 | 0x02, 0xda, 0xfa, 0x9d, 0x61, 0x62, 0x63, 0x00, 0xea, 0x00, 0x00, |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 24 | 0x05, 0xaa, 0x8e, 0x31, 0x00, |
| 25 | 0x02, 0xfa, 0x8e, 0x34, 0x00, |
| 26 | 0x02, 0xd2, 0x8e, 0x32, 0x00, |
| 27 | 0x03, 0x82, 0x9d, 0x01, 0xe0, 0x00, 0x00, |
| 28 | 0x02, 0xca, 0xb5, 0x61, 0x62, 0x61, 0x62, 0x61, 0x62, 0x00, |
| 29 | 0x00, |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 30 | 1 |
| 31 | }; |
| 32 | |
Jeff Thompson | f9d4bfd | 2013-08-21 11:27:24 -0700 | [diff] [blame] | 33 | static void dumpInterest(const Interest &interest) |
| 34 | { |
| 35 | cout << "name: " << interest.getName().to_uri() << endl; |
| 36 | cout << "minSuffixComponents: "; |
| 37 | if (interest.getMinSuffixComponents() >= 0) |
| 38 | cout << interest.getMinSuffixComponents() << endl; |
| 39 | else |
| 40 | cout << "<none>" << endl; |
| 41 | cout << "maxSuffixComponents: "; |
| 42 | if (interest.getMaxSuffixComponents() >= 0) |
| 43 | cout << interest.getMaxSuffixComponents() << endl; |
| 44 | else |
| 45 | cout << "<none>" << endl; |
| 46 | cout << "publisherPublicKeyDigest: " |
| 47 | << (interest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ? toHex(interest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()) : "<none>") << endl; |
| 48 | cout << "exclude: " |
| 49 | << (interest.getExclude().getEntryCount() > 0 ? interest.getExclude().toUri() : "<none>") << endl; |
| 50 | cout << "lifetimeMilliseconds: "; |
| 51 | if (interest.getInterestLifetimeMilliseconds() >= 0) |
| 52 | cout << interest.getInterestLifetimeMilliseconds() << endl; |
| 53 | else |
| 54 | cout << "<none>" << endl; |
| 55 | cout << "childSelector: "; |
| 56 | if (interest.getChildSelector() >= 0) |
| 57 | cout << interest.getChildSelector() << endl; |
| 58 | else |
| 59 | cout << "<none>" << endl; |
| 60 | cout << "answerOriginKind: "; |
| 61 | if (interest.getAnswerOriginKind() >= 0) |
| 62 | cout << interest.getAnswerOriginKind() << endl; |
| 63 | else |
| 64 | cout << "<none>" << endl; |
| 65 | cout << "scope: "; |
| 66 | if (interest.getScope() >= 0) |
| 67 | cout << interest.getScope() << endl; |
| 68 | else |
| 69 | cout << "<none>" << endl; |
| 70 | cout << "nonce: " |
| 71 | << (interest.getNonce().size() > 0 ? toHex(interest.getNonce()) : "<none>") << endl; |
| 72 | } |
| 73 | |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 74 | int main(int argc, char** argv) |
| 75 | { |
| 76 | try { |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 77 | Interest interest; |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 78 | interest.wireDecode(Interest1, sizeof(Interest1)); |
Jeff Thompson | f9d4bfd | 2013-08-21 11:27:24 -0700 | [diff] [blame] | 79 | cout << "Interest:" << endl; |
| 80 | dumpInterest(interest); |
Jeff Thompson | 2fb4b1b | 2013-07-01 15:10:43 -0700 | [diff] [blame] | 81 | |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 82 | ptr_lib::shared_ptr<vector<unsigned char> > encoding = interest.wireEncode(); |
Jeff Thompson | ed4f373 | 2013-08-15 17:34:34 -0700 | [diff] [blame] | 83 | cout << endl << "Re-encoded interest " << toHex(*encoding) << endl; |
Jeff Thompson | 0d567da | 2013-07-14 22:10:21 -0700 | [diff] [blame] | 84 | |
Jeff Thompson | 06f824a | 2013-07-08 17:14:30 -0700 | [diff] [blame] | 85 | Interest reDecodedInterest; |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 86 | reDecodedInterest.wireDecode(*encoding); |
Jeff Thompson | f9d4bfd | 2013-08-21 11:27:24 -0700 | [diff] [blame] | 87 | cout << "Re-decoded Interest:" << endl; |
| 88 | dumpInterest(reDecodedInterest); |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 89 | } catch (exception &e) { |
Jeff Thompson | 8b66600 | 2013-07-08 01:16:26 -0700 | [diff] [blame] | 90 | cout << "exception: " << e.what() << endl; |
Jeff Thompson | 7afc98e | 2013-06-27 14:33:53 -0700 | [diff] [blame] | 91 | } |
Jeff Thompson | 3b3aabf | 2013-06-21 16:50:20 -0700 | [diff] [blame] | 92 | return 0; |
| 93 | } |