Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Jeff Thompson | 4c89ad6 | 2013-06-28 12:50:13 -0700 | [diff] [blame] | 8 | #include <stdexcept> |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 9 | #include <ndn-cpp/interest.hpp> |
| 10 | #include <ndn-cpp/data.hpp> |
| 11 | #include <ndn-cpp/forwarding-entry.hpp> |
| 12 | #include <ndn-cpp/encoding/binary-xml-wire-format.hpp> |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 13 | #include "../c/encoding/binary-xml-interest.h" |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 14 | #include "../c/encoding/binary-xml-data.h" |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 15 | #include "../c/encoding/binary-xml-forwarding-entry.h" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 16 | #include "binary-xml-encoder.hpp" |
| 17 | #include "binary-xml-decoder.hpp" |
Jeff Thompson | 4c89ad6 | 2013-06-28 12:50:13 -0700 | [diff] [blame] | 18 | |
Jeff Thompson | 1f3f517 | 2013-07-01 19:02:36 -0700 | [diff] [blame] | 19 | using namespace std; |
| 20 | |
Jeff Thompson | 4c89ad6 | 2013-06-28 12:50:13 -0700 | [diff] [blame] | 21 | namespace ndn { |
| 22 | |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 23 | namespace c { |
| 24 | |
| 25 | class Exclude : public ndn::Exclude |
| 26 | { |
| 27 | public: |
| 28 | void |
| 29 | get(struct ndn_Exclude& excludeStruct) const |
| 30 | { |
| 31 | if (excludeStruct.maxEntries < size()) |
| 32 | throw runtime_error("excludeStruct.maxEntries must be >= this exclude getEntryCount()"); |
| 33 | |
| 34 | int entries = 0; |
| 35 | for (Exclude::const_reverse_iterator i = rbegin (); i != rend (); i++) |
| 36 | { |
| 37 | if (!i->first.empty()) |
| 38 | { |
| 39 | excludeStruct.entries[entries].type = ndn_Exclude_COMPONENT; |
| 40 | excludeStruct.entries[entries].component.value.value = const_cast<uint8_t*>(i->first.getValue().buf()); |
| 41 | excludeStruct.entries[entries].component.value.length = i->first.getValue().size(); |
| 42 | ++entries; |
| 43 | } |
| 44 | if (i->second) |
| 45 | { |
| 46 | excludeStruct.entries[entries].type = ndn_Exclude_ANY; |
| 47 | ++entries; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | excludeStruct.nEntries = entries; |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | set(const struct ndn_Exclude& excludeStruct) |
| 56 | { |
| 57 | clear(); |
| 58 | |
| 59 | if (excludeStruct.nEntries == 0) |
| 60 | return; |
| 61 | |
| 62 | int i = 0; |
| 63 | if (excludeStruct.entries[i].type == ndn_Exclude_ANY) { |
| 64 | appendExclude("/", true); |
| 65 | i++; |
| 66 | } |
| 67 | |
| 68 | while (i < excludeStruct.nEntries) { |
| 69 | ndn_ExcludeEntry *entry = &excludeStruct.entries[i]; |
| 70 | |
| 71 | if (entry->type != ndn_Exclude_COMPONENT) |
| 72 | throw runtime_error("unrecognized ndn_ExcludeType"); |
| 73 | |
| 74 | Name::Component excludedComponent (entry->component.value.value, entry->component.value.length); |
| 75 | ++i; |
| 76 | entry = &excludeStruct.entries[i]; |
| 77 | |
| 78 | if (i < excludeStruct.nEntries) { |
| 79 | if (entry->type == ndn_Exclude_ANY) { |
| 80 | appendExclude(excludedComponent, true); |
| 81 | ++i; |
| 82 | } |
| 83 | else |
| 84 | appendExclude(excludedComponent, false); |
| 85 | } |
| 86 | else |
| 87 | appendExclude(excludedComponent, false); |
| 88 | } |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | class Name : public ndn::Name |
| 93 | { |
| 94 | public: |
| 95 | void |
| 96 | get(struct ndn_Name& nameStruct) const |
| 97 | { |
| 98 | if (nameStruct.maxComponents < size()) |
| 99 | throw runtime_error("nameStruct.maxComponents must be >= this name getNComponents()"); |
| 100 | |
| 101 | nameStruct.nComponents = size(); |
| 102 | for (size_t i = 0; i < nameStruct.nComponents; ++i) { |
| 103 | nameStruct.components[i].value.value = const_cast<uint8_t*>(ndn::Name::get(i).getValue().buf()); |
| 104 | nameStruct.components[i].value.length = ndn::Name::get(i).getValue().size(); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | set(const struct ndn_Name& nameStruct) |
| 110 | { |
| 111 | clear(); |
| 112 | for (size_t i = 0; i < nameStruct.nComponents; ++i) |
| 113 | append(nameStruct.components[i].value.value, nameStruct.components[i].value.length); |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | class Interest : public ndn::Interest |
| 118 | { |
| 119 | public: |
| 120 | void |
| 121 | get(struct ndn_Interest& interestStruct) const |
| 122 | { |
| 123 | reinterpret_cast<const c::Name&>(getName()).get(interestStruct.name); |
| 124 | interestStruct.minSuffixComponents = getMinSuffixComponents(); |
| 125 | interestStruct.maxSuffixComponents = getMaxSuffixComponents(); |
| 126 | // publisherPublicKeyDigest_.get(interestStruct.publisherPublicKeyDigest); |
| 127 | reinterpret_cast<const c::Exclude&>(getExclude()).get(interestStruct.exclude); |
| 128 | interestStruct.childSelector = getChildSelector(); |
| 129 | interestStruct.answerOriginKind = getMustBeFresh() ? |
| 130 | (ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED) |
| 131 | : |
| 132 | (ndn_Interest_ANSWER_CONTENT_STORE | ndn_Interest_ANSWER_GENERATED | ndn_Interest_ANSWER_STALE); |
| 133 | interestStruct.scope = getScope(); |
| 134 | interestStruct.interestLifetimeMilliseconds = getInterestLifetime(); |
| 135 | |
| 136 | interestStruct.nonce.length = 4; |
| 137 | interestStruct.nonce.value = const_cast<uint8_t*>(reinterpret_cast<const uint8_t *>(getNonce())); |
| 138 | } |
| 139 | |
| 140 | void |
| 141 | set(const struct ndn_Interest& interestStruct) |
| 142 | { |
| 143 | reinterpret_cast<c::Name&>(getName()).set(interestStruct.name); |
| 144 | setMinSuffixComponents(interestStruct.minSuffixComponents); |
| 145 | setMaxSuffixComponents(interestStruct.maxSuffixComponents); |
| 146 | |
| 147 | // publisherPublicKeyDigest_.set(interestStruct.publisherPublicKeyDigest); |
| 148 | |
| 149 | reinterpret_cast<c::Exclude&>(getExclude()).set(interestStruct.exclude); |
| 150 | setChildSelector(interestStruct.childSelector); |
| 151 | // answerOriginKind_ = interestStruct.answerOriginKind; |
| 152 | setScope(interestStruct.scope); |
| 153 | setInterestLifetime(interestStruct.interestLifetimeMilliseconds); |
| 154 | |
| 155 | setNonce(*reinterpret_cast<uint32_t*>(interestStruct.nonce.value)); |
| 156 | } |
| 157 | }; |
| 158 | |
| 159 | class Data : public ndn::Data |
| 160 | { |
| 161 | public: |
| 162 | void |
| 163 | get(struct ndn_Data& dataStruct) const |
| 164 | { |
| 165 | // signature_->get(dataStruct.signature); |
| 166 | // name_.get(dataStruct.name); |
| 167 | // metaInfo_.get(dataStruct.metaInfo); |
| 168 | // content_.get(dataStruct.content); |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | set(const struct ndn_Data& dataStruct) |
| 173 | { |
| 174 | // signature_->set(dataStruct.signature); |
| 175 | // name_.set(dataStruct.name); |
| 176 | // metaInfo_.set(dataStruct.metaInfo); |
| 177 | // content_ = Blob(dataStruct.content); |
| 178 | } |
| 179 | }; |
| 180 | |
| 181 | class ForwardingEntry : public ndn::ForwardingEntry |
| 182 | { |
| 183 | public: |
| 184 | void |
| 185 | get(struct ndn_ForwardingEntry& forwardingEntryStruct) const |
| 186 | { |
| 187 | reinterpret_cast<const c::Name&>(getPrefix()).get(forwardingEntryStruct.prefix); |
| 188 | // publisherPublicKeyDigest_.get(forwardingEntryStruct.publisherPublicKeyDigest); |
| 189 | forwardingEntryStruct.faceId = getFaceId(); |
| 190 | // forwardingEntryStruct.forwardingFlags = getForwardingFlags(); |
| 191 | forwardingEntryStruct.freshnessSeconds = getFreshnessPeriod() / 1000; |
| 192 | |
| 193 | forwardingEntryStruct.action.length = getAction().size(); |
| 194 | if (getAction().size() > 0) |
| 195 | forwardingEntryStruct.action.value = (uint8_t *)&getAction(); |
| 196 | else |
| 197 | forwardingEntryStruct.action.value = 0; |
| 198 | } |
| 199 | |
| 200 | void |
| 201 | set(const struct ndn_ForwardingEntry& forwardingEntryStruct) |
| 202 | { |
| 203 | if (forwardingEntryStruct.action.value && forwardingEntryStruct.action.length > 0) |
| 204 | setAction(string(forwardingEntryStruct.action.value, forwardingEntryStruct.action.value + forwardingEntryStruct.action.length)); |
| 205 | else |
| 206 | setAction(""); |
| 207 | |
| 208 | Name prefix; |
| 209 | reinterpret_cast<c::Name&>(prefix).set(forwardingEntryStruct.prefix); |
| 210 | setPrefix(prefix); |
| 211 | // publisherPublicKeyDigest_.set(forwardingEntryStruct.publisherPublicKeyDigest); |
| 212 | setFaceId(forwardingEntryStruct.faceId); |
| 213 | // setForwardingFlags(forwardingEntryStruct.forwardingFlags); |
| 214 | setFreshnessPeriod(forwardingEntryStruct.freshnessSeconds * 1000); |
| 215 | } |
| 216 | }; |
| 217 | |
| 218 | } |
| 219 | |
| 220 | |
Jeff Thompson | fa181ac | 2013-08-02 19:00:51 -0700 | [diff] [blame] | 221 | // This is declared in the WireFormat class. |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 222 | WireFormat* |
| 223 | WireFormat::newInitialDefaultWireFormat() |
Jeff Thompson | fa181ac | 2013-08-02 19:00:51 -0700 | [diff] [blame] | 224 | { |
| 225 | return new BinaryXmlWireFormat(); |
| 226 | } |
| 227 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 228 | Blob |
| 229 | BinaryXmlWireFormat::encodeInterest(const Interest& interest) |
Jeff Thompson | 214c7be | 2013-07-08 15:23:00 -0700 | [diff] [blame] | 230 | { |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 231 | struct ndn_NameComponent nameComponents[100]; |
| 232 | struct ndn_ExcludeEntry excludeEntries[100]; |
Jeff Thompson | 214c7be | 2013-07-08 15:23:00 -0700 | [diff] [blame] | 233 | struct ndn_Interest interestStruct; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 234 | ndn_Interest_initialize |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 235 | (&interestStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]), |
| 236 | excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0])); |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 237 | reinterpret_cast<const c::Interest&>(interest).get(interestStruct); |
Jeff Thompson | 214c7be | 2013-07-08 15:23:00 -0700 | [diff] [blame] | 238 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 239 | BinaryXmlEncoder encoder; |
Jeff Thompson | aa02071 | 2013-08-08 21:20:06 -0700 | [diff] [blame] | 240 | ndn_Error error; |
| 241 | if ((error = ndn_encodeBinaryXmlInterest(&interestStruct, &encoder))) |
Jeff Thompson | 4affbf5 | 2013-10-18 14:36:46 -0700 | [diff] [blame] | 242 | throw runtime_error(ndn_getErrorString(error)); |
Jeff Thompson | 214c7be | 2013-07-08 15:23:00 -0700 | [diff] [blame] | 243 | |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 244 | return encoder.getOutput(); |
Jeff Thompson | 214c7be | 2013-07-08 15:23:00 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 247 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 248 | BinaryXmlWireFormat::decodeInterest(Interest& interest, const uint8_t *input, size_t inputLength) |
Jeff Thompson | 7c30eda | 2013-07-03 18:37:07 -0700 | [diff] [blame] | 249 | { |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 250 | struct ndn_NameComponent nameComponents[100]; |
| 251 | struct ndn_ExcludeEntry excludeEntries[100]; |
Jeff Thompson | 7c30eda | 2013-07-03 18:37:07 -0700 | [diff] [blame] | 252 | struct ndn_Interest interestStruct; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 253 | ndn_Interest_initialize |
Jeff Thompson | f084ec6 | 2013-07-09 12:32:52 -0700 | [diff] [blame] | 254 | (&interestStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]), |
| 255 | excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0])); |
Jeff Thompson | 7c30eda | 2013-07-03 18:37:07 -0700 | [diff] [blame] | 256 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 257 | BinaryXmlDecoder decoder(input, inputLength); |
Jeff Thompson | b0e4fad | 2013-07-08 01:16:48 -0700 | [diff] [blame] | 258 | ndn_Error error; |
Jeff Thompson | 94ddc27 | 2013-08-08 14:17:38 -0700 | [diff] [blame] | 259 | if ((error = ndn_decodeBinaryXmlInterest(&interestStruct, &decoder))) |
Jeff Thompson | 4affbf5 | 2013-10-18 14:36:46 -0700 | [diff] [blame] | 260 | throw runtime_error(ndn_getErrorString(error)); |
Jeff Thompson | 7c30eda | 2013-07-03 18:37:07 -0700 | [diff] [blame] | 261 | |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 262 | reinterpret_cast<c::Interest&>(interest).set(interestStruct); |
Jeff Thompson | 7c30eda | 2013-07-03 18:37:07 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 265 | Blob |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 266 | BinaryXmlWireFormat::encodeData(const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 267 | { |
| 268 | struct ndn_NameComponent nameComponents[100]; |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 269 | struct ndn_NameComponent keyNameComponents[100]; |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 270 | struct ndn_Data dataStruct; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 271 | ndn_Data_initialize |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 272 | (&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]), |
| 273 | keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0])); |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 274 | reinterpret_cast<const c::Data&>(data).get(dataStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 275 | |
Jeff Thompson | 3aa2d54 | 2013-12-10 18:14:22 -0800 | [diff] [blame] | 276 | BinaryXmlEncoder encoder(1500); |
Jeff Thompson | aa02071 | 2013-08-08 21:20:06 -0700 | [diff] [blame] | 277 | ndn_Error error; |
Jeff Thompson | 9c66170 | 2013-09-13 14:35:44 -0700 | [diff] [blame] | 278 | if ((error = ndn_encodeBinaryXmlData(&dataStruct, signedPortionBeginOffset, signedPortionEndOffset, &encoder))) |
Jeff Thompson | 4affbf5 | 2013-10-18 14:36:46 -0700 | [diff] [blame] | 279 | throw runtime_error(ndn_getErrorString(error)); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 280 | |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 281 | return encoder.getOutput(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 284 | void |
| 285 | BinaryXmlWireFormat::decodeData |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 286 | (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 287 | { |
| 288 | struct ndn_NameComponent nameComponents[100]; |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 289 | struct ndn_NameComponent keyNameComponents[100]; |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 290 | struct ndn_Data dataStruct; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 291 | ndn_Data_initialize |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 292 | (&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]), |
| 293 | keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0])); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 294 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 295 | BinaryXmlDecoder decoder(input, inputLength); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 296 | ndn_Error error; |
Jeff Thompson | 9c66170 | 2013-09-13 14:35:44 -0700 | [diff] [blame] | 297 | if ((error = ndn_decodeBinaryXmlData(&dataStruct, signedPortionBeginOffset, signedPortionEndOffset, &decoder))) |
Jeff Thompson | 4affbf5 | 2013-10-18 14:36:46 -0700 | [diff] [blame] | 298 | throw runtime_error(ndn_getErrorString(error)); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 299 | |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 300 | reinterpret_cast<c::Data&>(data).set(dataStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 303 | Blob |
| 304 | BinaryXmlWireFormat::encodeForwardingEntry(const ForwardingEntry& forwardingEntry) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 305 | { |
| 306 | struct ndn_NameComponent prefixNameComponents[100]; |
| 307 | struct ndn_ForwardingEntry forwardingEntryStruct; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 308 | ndn_ForwardingEntry_initialize |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 309 | (&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0])); |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 310 | reinterpret_cast<const c::ForwardingEntry&>(forwardingEntry).get(forwardingEntryStruct); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 311 | |
| 312 | BinaryXmlEncoder encoder; |
| 313 | ndn_Error error; |
| 314 | if ((error = ndn_encodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &encoder))) |
Jeff Thompson | 4affbf5 | 2013-10-18 14:36:46 -0700 | [diff] [blame] | 315 | throw runtime_error(ndn_getErrorString(error)); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 316 | |
| 317 | return encoder.getOutput(); |
| 318 | } |
| 319 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 320 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 321 | BinaryXmlWireFormat::decodeForwardingEntry(ForwardingEntry& forwardingEntry, const uint8_t *input, size_t inputLength) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 322 | { |
| 323 | struct ndn_NameComponent prefixNameComponents[100]; |
| 324 | struct ndn_ForwardingEntry forwardingEntryStruct; |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 325 | ndn_ForwardingEntry_initialize |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 326 | (&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0])); |
| 327 | |
| 328 | BinaryXmlDecoder decoder(input, inputLength); |
| 329 | ndn_Error error; |
| 330 | if ((error = ndn_decodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &decoder))) |
Jeff Thompson | 4affbf5 | 2013-10-18 14:36:46 -0700 | [diff] [blame] | 331 | throw runtime_error(ndn_getErrorString(error)); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 332 | |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 333 | reinterpret_cast<c::ForwardingEntry&>(forwardingEntry).set(forwardingEntryStruct); |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Jeff Thompson | 4c89ad6 | 2013-06-28 12:50:13 -0700 | [diff] [blame] | 336 | } |