/** * Imitate Interest::get(InterestLite& interestLite). * @param interest The Python Interest object to get from. * @param interestLite The InterestLite to update. * @param pool1 This calls pool1.reset to store a temporary value which must * remain valid while interestLite is used. * @param pool2 This calls pool2.reset to store a temporary value which must * remain valid while interestLite is used. */ static void toInterestLite (PyObject* interest, InterestLite& interestLite, PyObjectRef& pool1, PyObjectRef& pool2) { PyObjectRef name(PyObject_CallMethodObjArgs(interest, str.getName, NULL)); toNameLite(name, interestLite.getName()); // If the value is None, PyInt_AsLong returns -1 as desired. interestLite.setMinSuffixComponents ((int)toLongByMethod(interest, str.getMinSuffixComponents)); interestLite.setMaxSuffixComponents ((int)toLongByMethod(interest, str.getMaxSuffixComponents)); PyObjectRef keyLocator(PyObject_CallMethodObjArgs(interest, str.getKeyLocator, NULL)); toKeyLocatorLite(keyLocator, interestLite.getKeyLocator()); PyObjectRef exclude(PyObject_CallMethodObjArgs(interest, str.getExclude, NULL)); toExcludeLite(exclude, interestLite.getExclude()); interestLite.setChildSelector ((int)toLongByMethod(interest, str.getChildSelector)); interestLite.setMustBeFresh(toBoolByMethod(interest, str.getMustBeFresh)); interestLite.setInterestLifetimeMilliseconds (toDoubleByMethod(interest, str.getInterestLifetimeMilliseconds)); interestLite.setNonce(toBlobLiteByMethod(interest, str.getNonce)); interestLite.setApplicationParameters(toBlobLiteByMethod(interest, str.getApplicationParameters)); PyObjectRef forwardingHint (PyObject_CallMethodObjArgs(interest, str.getForwardingHint, NULL)); if (toLongByMethod(forwardingHint, str.size) > 0) { // InterestLite only stores the encoded delegation set. Cache the wire // encoding in pool2 long enough to encode the Interest. // TODO: Support the wireFormat param. // TODO: Catch exceptions from wireEncode. pool2.reset(PyObject_CallMethodObjArgs (forwardingHint, str.wireEncode, NULL)); PyObjectRef forwardingHintWireEncodingArray (PyObject_GetAttr(pool2, str._array)); interestLite.setForwardingHintWireEncoding (toBlobLiteFromArray(forwardingHintWireEncodingArray)); } else interestLite.setForwardingHintWireEncoding(BlobLite()); // TODO: Support the wireFormat param. // TODO: Catch exceptions from getLinkWireEncoding. pool1.reset(PyObject_CallMethodObjArgs(interest, str.getLinkWireEncoding, NULL)); PyObjectRef linkWireEncodingArray(PyObject_GetAttr(pool1, str._array)); if (linkWireEncodingArray.obj == Py_None) interestLite.setLinkWireEncoding(BlobLite()); else interestLite.setLinkWireEncoding(toBlobLiteFromArray(linkWireEncodingArray)); interestLite.setSelectedDelegationIndex ((int)toLongByMethod(interest, str.getSelectedDelegationIndex)); }
// 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()); 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)); }
/** * Imitate Interest::get(InterestLite& interestLite). * @param interest The Python Interest object to get from. * @param interestLite The InterestLite to update. * @param pool1 This calls pool1.reset to store a temporary value which must * remain valid while interestLite is used. */ static void toInterestLite (PyObject* interest, InterestLite& interestLite, PyObjectRef& pool1) { PyObjectRef name(PyObject_CallMethodObjArgs(interest, str.getName, NULL)); toNameLite(name, interestLite.getName()); // If the value is None, PyInt_AsLong returns -1 as desired. interestLite.setMinSuffixComponents ((int)toLongByMethod(interest, str.getMinSuffixComponents)); interestLite.setMaxSuffixComponents ((int)toLongByMethod(interest, str.getMaxSuffixComponents)); PyObjectRef keyLocator(PyObject_CallMethodObjArgs(interest, str.getKeyLocator, NULL)); toKeyLocatorLite(keyLocator, interestLite.getKeyLocator()); PyObjectRef exclude(PyObject_CallMethodObjArgs(interest, str.getExclude, NULL)); toExcludeLite(exclude, interestLite.getExclude()); interestLite.setChildSelector ((int)toLongByMethod(interest, str.getChildSelector)); interestLite.setMustBeFresh(toBoolByMethod(interest, str.getMustBeFresh)); interestLite.setInterestLifetimeMilliseconds (toDoubleByMethod(interest, str.getInterestLifetimeMilliseconds)); // TODO: Support the wireFormat param. // TODO: Catch exceptions from getLinkWireEncoding. pool1.reset(PyObject_CallMethodObjArgs(interest, str.getLinkWireEncoding, NULL)); PyObjectRef linkWireEncodingArray(PyObject_GetAttr(pool1, str._array)); if (linkWireEncodingArray.obj == Py_None) interestLite.setLinkWireEncoding(BlobLite()); else interestLite.setLinkWireEncoding(toBlobLiteFromArray(linkWireEncodingArray)); interestLite.setSelectedDelegationIndex ((int)toLongByMethod(interest, str.getSelectedDelegationIndex)); }