Beispiel #1
0
// Imitate Data::set(const DataLite& dataLite).
static void
setData(PyObject* data, const DataLite& dataLite)
{
  PyObject* signatureClassName = getSignatureClassName(dataLite.getSignature());
  if (!signatureClassName)
    // TODO: Handle the error "Unrecognized signature type".
    return;

  PyObjectRef signatureClass(PyObject_GetAttr(PYNDN_MODULE, signatureClassName));
  PyObjectRef tempSignature(PyObject_CallObject(signatureClass, NULL));
  PyObjectRef ignoreResult1(PyObject_CallMethodObjArgs
    (data, str.setSignature, tempSignature.obj, NULL));
  // Now use the signature object that was copied into data.
  PyObjectRef signature(PyObject_CallMethodObjArgs(data, str.getSignature, NULL));
  setSignature(signature, dataLite.getSignature());

  PyObjectRef name(PyObject_CallMethodObjArgs(data, str.getName, NULL));
  setName(name, dataLite.getName());

  PyObjectRef metaInfo(PyObject_CallMethodObjArgs(data, str.getMetaInfo, NULL));
  setMetaInfo(metaInfo, dataLite.getMetaInfo());

  PyObjectRef content(makeBlob(dataLite.getContent()));
  PyObjectRef ignoreResult2(PyObject_CallMethodObjArgs
    (data, str.setContent, content.obj, NULL));
}
Beispiel #2
0
// Imitate Data::get(DataLite& dataLite).
static void
toDataLite(PyObject* data, DataLite& dataLite)
{
  PyObjectRef signature(PyObject_CallMethodObjArgs(data, str.getSignature, NULL));
  toSignatureLite(signature, dataLite.getSignature());

  PyObjectRef name(PyObject_CallMethodObjArgs(data, str.getName, NULL));
  toNameLite(name, dataLite.getName());

  PyObjectRef metaInfo(PyObject_CallMethodObjArgs(data, str.getMetaInfo, NULL));
  toMetaInfoLite(metaInfo, dataLite.getMetaInfo());

  dataLite.setContent(toBlobLiteByMethod(data, str.getContent));
}