/**
* CPython 3 C extension.
*/
#include
#include
#include "bitstream.h"
#include
struct field_info_t;
typedef void (*pack_field_t)(struct bitstream_writer_t *self_p,
PyObject *value_p,
struct field_info_t *field_info_p);
typedef PyObject *(*unpack_field_t)(struct bitstream_reader_t *self_p,
struct field_info_t *field_info_p);
struct field_info_t {
pack_field_t pack;
unpack_field_t unpack;
int number_of_bits;
bool is_padding;
union {
struct {
int64_t lower;
int64_t upper;
} s;
struct {
uint64_t upper;
} u;
} limits;
};
struct info_t {
int number_of_bits;
int number_of_fields;
int number_of_non_padding_fields;
struct field_info_t fields[1];
};
struct compiled_format_t {
PyObject_HEAD
struct info_t *info_p;
PyObject *format_p;
};
struct compiled_format_dict_t {
PyObject_HEAD
struct info_t *info_p;
PyObject *format_p;
PyObject *names_p;
};
static const char* pickle_version_key = "_pickle_version";
static int pickle_version = 1;
static PyObject *compiled_format_new(PyTypeObject *type_p,
PyObject *args_p,
PyObject *kwargs_p);
static int compiled_format_init(struct compiled_format_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static int compiled_format_init_inner(struct compiled_format_t *self_p,
PyObject *format_p);
static void compiled_format_dealloc(struct compiled_format_t *self_p);
static PyObject *m_compiled_format_pack(struct compiled_format_t *self_p,
PyObject *args_p);
static PyObject *m_compiled_format_unpack(struct compiled_format_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static PyObject *m_compiled_format_pack_into(struct compiled_format_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static PyObject *m_compiled_format_unpack_from(struct compiled_format_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static PyObject *m_compiled_format_calcsize(struct compiled_format_t *self_p);
static PyObject *m_compiled_format_copy(struct compiled_format_t *self_p);
static PyObject *m_compiled_format_deepcopy(struct compiled_format_t *self_p,
PyObject *args_p);
static PyObject *m_compiled_format_getstate(struct compiled_format_t *self_p,
PyObject *args_p);
static PyObject *m_compiled_format_setstate(struct compiled_format_t *self_p,
PyObject *args_p);
static PyObject *compiled_format_dict_new(PyTypeObject *type_p,
PyObject *args_p,
PyObject *kwargs_p);
static int compiled_format_dict_init(struct compiled_format_dict_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static int compiled_format_dict_init_inner(struct compiled_format_dict_t *self_p,
PyObject *format_p,
PyObject *names_p);
static void compiled_format_dict_dealloc(struct compiled_format_dict_t *self_p);
static PyObject *m_compiled_format_dict_pack(struct compiled_format_dict_t *self_p,
PyObject *data_p);
static PyObject *m_compiled_format_dict_unpack(
struct compiled_format_dict_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static PyObject *m_compiled_format_dict_pack_into(
struct compiled_format_dict_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static PyObject *m_compiled_format_dict_unpack_from(
struct compiled_format_dict_t *self_p,
PyObject *args_p,
PyObject *kwargs_p);
static PyObject *m_compiled_format_dict_calcsize(
struct compiled_format_dict_t *self_p);
static PyObject *m_compiled_format_dict_copy(
struct compiled_format_dict_t *self_p);
static PyObject *m_compiled_format_dict_deepcopy(
struct compiled_format_dict_t *self_p,
PyObject *args_p);
static PyObject *m_compiled_format_dict_getstate(struct compiled_format_dict_t *self_p,
PyObject *args_p);
static PyObject *m_compiled_format_dict_setstate(struct compiled_format_dict_t *self_p,
PyObject *args_p);
PyDoc_STRVAR(pack___doc__,
"pack(fmt, *args)\n"
"--\n"
"\n");
PyDoc_STRVAR(compiled_format_pack___doc__,
"pack(*args)\n"
"--\n"
"\n");
PyDoc_STRVAR(unpack___doc__,
"unpack(fmt, data, allow_truncated=False)\n"
"--\n"
"\n");
PyDoc_STRVAR(compiled_format_unpack___doc__,
"unpack(data, allow_truncated=False)\n"
"--\n"
"\n");
PyDoc_STRVAR(pack_into___doc__,
"pack_into(fmt, buf, offset, *args, **kwargs)\n"
"--\n"
"\n");
PyDoc_STRVAR(compiled_format_pack_into___doc__,
"pack_into(buf, offset, *args, **kwargs)\n"
"--\n"
"\n");
PyDoc_STRVAR(unpack_from___doc__,
"unpack_from(fmt, data, offset=0, allow_truncated=False)\n"
"--\n"
"\n");
PyDoc_STRVAR(compiled_format_unpack_from___doc__,
"unpack_from(data, offset=0, allow_truncated=False)\n"
"--\n"
"\n");
PyDoc_STRVAR(calcsize___doc__,
"calcsize(fmt)\n"
"--\n"
"\n");
PyDoc_STRVAR(compiled_format_calcsize___doc__,
"calcsize()\n"
"--\n"
"\n");
static PyObject *py_zero_p = NULL;
static struct PyMethodDef compiled_format_methods[] = {
{
"pack",
(PyCFunction)m_compiled_format_pack,
METH_VARARGS,
compiled_format_pack___doc__
},
{
"unpack",
(PyCFunction)m_compiled_format_unpack,
METH_VARARGS | METH_KEYWORDS,
compiled_format_unpack___doc__
},
{
"pack_into",
(PyCFunction)m_compiled_format_pack_into,
METH_VARARGS | METH_KEYWORDS,
compiled_format_pack_into___doc__
},
{
"unpack_from",
(PyCFunction)m_compiled_format_unpack_from,
METH_VARARGS | METH_KEYWORDS,
compiled_format_unpack_from___doc__
},
{
"calcsize",
(PyCFunction)m_compiled_format_calcsize,
METH_NOARGS,
compiled_format_calcsize___doc__
},
{
"__copy__",
(PyCFunction)m_compiled_format_copy,
METH_NOARGS
},
{
"__deepcopy__",
(PyCFunction)m_compiled_format_deepcopy,
METH_VARARGS
},
{
"__getstate__",
(PyCFunction)m_compiled_format_getstate,
METH_NOARGS
},
{
"__setstate__",
(PyCFunction)m_compiled_format_setstate,
METH_O
},
{ NULL }
};
static PyTypeObject compiled_format_type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "bitstruct.c.CompiledFormat",
.tp_doc = NULL,
.tp_basicsize = sizeof(struct compiled_format_t),
.tp_itemsize