static bool decode_buffer_from_obj(DecodeBuffer* dest, PyObject* obj) { dest->stringiobuf = PyObject_GetAttr(obj, INTERN_STRING(cstringio_buf)); if (!dest->stringiobuf) { return false; } if (!PycStringIO_InputCheck(dest->stringiobuf)) { free_decodebuf(dest); PyErr_SetString(PyExc_TypeError, "expecting stringio input"); return false; } dest->refill_callable = PyObject_GetAttr(obj, INTERN_STRING(cstringio_refill)); if(!dest->refill_callable) { free_decodebuf(dest); return false; } if (!PyCallable_Check(dest->refill_callable)) { free_decodebuf(dest); PyErr_SetString(PyExc_TypeError, "expecting callable"); return false; } return true; }
static PyObject* decode_binary(PyObject *self, PyObject *args) { PyObject* output_obj = NULL; PyObject* transport = NULL; PyObject* typeargs = NULL; StructTypeArgs parsedargs; DecodeBuffer input = {}; if (!PyArg_ParseTuple(args, "OOO", &output_obj, &transport, &typeargs)) { return NULL; } if (!parse_struct_args(&parsedargs, typeargs)) { return NULL; } if (!decode_buffer_from_obj(&input, transport)) { return NULL; } if (!decode_struct(&input, output_obj, parsedargs.spec)) { free_decodebuf(&input); return NULL; } free_decodebuf(&input); Py_RETURN_NONE; }
static PyObject* decode_binary(PyObject *self, PyObject *args) { PyObject* output_obj = NULL; PyObject* transport = NULL; PyObject* typeargs = NULL; StructTypeArgs parsedargs; PyObject* string_limit_obj = NULL; PyObject* container_limit_obj = NULL; long string_limit = 0; long container_limit = 0; DecodeBuffer input = {0, 0}; PyObject* ret = NULL; if (!PyArg_ParseTuple(args, "OOOOO", &output_obj, &transport, &typeargs, &string_limit_obj, &container_limit_obj)) { return NULL; } string_limit = as_long_or(string_limit_obj, INT32_MAX); container_limit = as_long_or(container_limit_obj, INT32_MAX); if (!parse_struct_args(&parsedargs, typeargs)) { return NULL; } if (!decode_buffer_from_obj(&input, transport)) { return NULL; } ret = decode_struct(&input, output_obj, parsedargs.klass, parsedargs.spec, string_limit, container_limit); free_decodebuf(&input); return ret; }