void pycbc_viewresult_addrow(pycbc_ViewResult *vres, pycbc_MultiResult *mres, const void *data, size_t n) { PyObject *j; int rv; rv = pycbc_tc_simple_decode(&j, data, n, PYCBC_FMT_JSON); if (rv != 0) { pycbc_multiresult_adderr(mres); pycbc_tc_simple_decode(&j, data, n, PYCBC_FMT_BYTES); } PyList_Append(vres->rows, j); Py_DECREF(j); }
/** * This callback does things a bit differently. * Instead of using a MultiResult, we use a single HttpResult object. * We won't ever have "multiple" http objects. */ static void http_complete_callback(lcb_http_request_t req, lcb_t instance, const void *cookie, lcb_error_t err, const lcb_http_resp_t *resp) { pycbc_HttpResultObject *htres = (pycbc_HttpResultObject*)cookie; htres->rc = err; htres->htcode = resp->v.v0.status; CB_THR_END(htres->parent); if (resp->v.v0.nbytes) { pycbc_tc_simple_decode(&htres->http_data, resp->v.v0.bytes, resp->v.v0.nbytes, htres->format); if (!htres->http_data) { PyErr_Clear(); htres->http_data = PyBytes_FromStringAndSize(resp->v.v0.bytes, resp->v.v0.nbytes); } } else { htres->http_data = Py_None; Py_INCREF(Py_None); } CB_THR_BEGIN(htres->parent); (void)instance; (void)req; }
static PyObject * decode_key(PyObject *self, PyObject *args) { int rv; char *buf; PyObject *bobj; Py_ssize_t plen; rv = PyArg_ParseTuple(args, "O", &bobj); if (!rv) { return NULL; } rv = PyBytes_AsStringAndSize(bobj, &buf, &plen); if (rv < 0) { return NULL; } rv = pycbc_tc_simple_decode(&bobj, buf, plen, PYCBC_FMT_UTF8); if (rv < 0) { return NULL; } (void)self; return bobj; }
static PyObject * decode_value(PyObject *self, PyObject *args) { PyObject *flagsobj; PyObject *vobj; char *buf; Py_ssize_t nbuf; int rv; lcb_uint32_t flags; rv = PyArg_ParseTuple(args, "OO", &vobj, &flagsobj); if (!rv) { return NULL; } rv = PyBytes_AsStringAndSize(vobj, &buf, &nbuf); if (rv < 0) { return NULL; } rv = pycbc_get_u32(flagsobj, &flags); if (rv < 0) { return NULL; } rv = pycbc_tc_simple_decode(&vobj, buf, nbuf, flags); if (rv < 0) { return NULL; } (void)self; return vobj; }
static void get_data(pycbc_HttpResult *htres, const void *data, size_t ndata) { PyObject *o = NULL; if (data == NULL) { if (!htres->http_data) { htres->http_data = Py_None; Py_INCREF(Py_None); } return; } pycbc_tc_simple_decode(&o, data, ndata, htres->format); if (!o) { PyErr_Clear(); htres->http_data = PyBytes_FromStringAndSize(data, ndata); } if ((htres->htflags & PYCBC_HTRES_F_CHUNKED) && htres->http_data && PyList_Check(htres->http_data)) { /** * If we have a list here, then it means we got an error and have to * start populating it. Otherwise, we handle as usual */ PyList_Append(htres->http_data, o); } else { Py_XDECREF(htres->http_data); htres->http_data = o; } }
static int add_view_field(PyObject *dd, PyObject *k, const void *v, size_t n) { PyObject *tmp; int rv; if (!n) { return 0; } rv = pycbc_tc_simple_decode(&tmp, v, n, PYCBC_FMT_JSON); if (rv != 0) { return rv; } PyDict_SetItem(dd, k, tmp); Py_XDECREF(tmp); return 0; }
static PyObject * mk_sd_tuple(const lcb_SDENTRY *ent) { PyObject *val = NULL; PyObject *ret; if (ent->status == LCB_SUCCESS && ent->nvalue != 0) { int rv = pycbc_tc_simple_decode(&val, ent->value, ent->nvalue, PYCBC_FMT_JSON); if (rv != 0) { return NULL; } } if (val == NULL) { val = Py_None; Py_INCREF(Py_None); } ret = Py_BuildValue("(iO)", ent->status, val); Py_DECREF(val); return ret; }