Example #1
0
void
Tlv0_2WireFormat::decodeInterest
  (Interest& interest, const uint8_t *input, size_t inputLength,
   size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
{
  struct ndn_NameComponent nameComponents[100];
  struct ndn_ExcludeEntry excludeEntries[100];
  struct ndn_NameComponent keyNameComponents[100];
  InterestLite interestLite
    (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
     excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0]),
     keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));

  ndn_Error error;
  if ((error = Tlv0_2WireFormatLite::decodeInterest
       (interestLite, input, inputLength, signedPortionBeginOffset,
        signedPortionEndOffset)))
    throw runtime_error(ndn_getErrorString(error));

  if (interestLite.getForwardingHintWireEncoding().buf()) {
    // Throw any decoding exceptions now before calling set.
    DelegationSet delegationSet;
    decodeDelegationSet
      (delegationSet, interestLite.getForwardingHintWireEncoding().buf(),
       interestLite.getForwardingHintWireEncoding().size());
  }

  interest.set(interestLite, *this);
}
Example #2
0
// Imitate Interest::set(const InterestLite& interestLite).
static void
setInterest(PyObject* interest, const InterestLite& interestLite)
{
  PyObjectRef name(PyObject_CallMethodObjArgs(interest, str.getName, NULL));
  setName(name, interestLite.getName());

  // If the value is -1, Interest.setMinSuffixComponents will set to None as desired.
  callMethodFromLong
    (interest, str.setMinSuffixComponents, interestLite.getMinSuffixComponents());
  callMethodFromLong
    (interest, str.setMaxSuffixComponents, interestLite.getMaxSuffixComponents());

  PyObjectRef keyLocator(PyObject_CallMethodObjArgs
    (interest, str.getKeyLocator, NULL));
  setKeyLocator(keyLocator, interestLite.getKeyLocator());

  PyObjectRef exclude(PyObject_CallMethodObjArgs
    (interest, str.getExclude, NULL));
  setExclude(exclude, interestLite.getExclude());

  callMethodFromLong
    (interest, str.setChildSelector, interestLite.getChildSelector());
  callMethodFromBool
    (interest, str.setMustBeFresh, interestLite.getMustBeFresh());
  callMethodFromDouble
    (interest, str.setInterestLifetimeMilliseconds,
     interestLite.getInterestLifetimeMilliseconds());
  PyObjectRef parameters(makeBlob(interestLite.getApplicationParameters()));
  PyObjectRef ignoreResult3(PyObject_CallMethodObjArgs
    (interest, str.setApplicationParameters, parameters.obj, NULL));

  if (interestLite.getForwardingHintWireEncoding().buf()) {
    // InterestLite only stores the encoded delegation set.
    PyObjectRef forwardingHintWireEncoding
      (makeBlob(interestLite.getForwardingHintWireEncoding()));
    PyObjectRef forwardingHint
      (PyObject_CallMethodObjArgs(interest, str.getForwardingHint, NULL));
    // TODO: Catch exceptions from wireDecode.
    PyObjectRef ignoreResult(PyObject_CallMethodObjArgs
      (forwardingHint, str.wireDecode, forwardingHintWireEncoding.obj, NULL));
  }

  if (interestLite.getLinkWireEncoding().buf()) {
    PyObjectRef linkWireEncoding(makeBlob(interestLite.getLinkWireEncoding()));
    // TODO: Support the wireFormat param.
    PyObjectRef ignoreResult(PyObject_CallMethodObjArgs
      (interest, str.setLinkWireEncoding, linkWireEncoding.obj, NULL));
  }
  else
    PyObjectRef ignoreResult1(PyObject_CallMethodObjArgs
      (interest, str.unsetLink, NULL));

  callMethodFromLong
    (interest, str.setSelectedDelegationIndex,
     interestLite.getSelectedDelegationIndex());

  // Set the nonce last so that getNonceChangeCount_ is set correctly.
  PyObjectRef nonce(makeBlob(interestLite.getNonce()));
  PyObjectRef ignoreResult2(PyObject_CallMethodObjArgs
    (interest, str.setNonce, nonce.obj, NULL));
}