1 #include "pyoggpackbuff.h"
3 #include "_oggmodule.h"
5 /************************************************************
7 ************************************************************/
9 char py_oggpack_buffer_doc
[] = "";
11 static void py_oggpack_buffer_dealloc(PyObject
*);
12 static PyObject
* py_oggpack_buffer_getattr(PyObject
*, char *);
13 static PyObject
*py_oggpack_repr(PyObject
*self
);
15 FDEF(oggpack_reset
) "";
16 FDEF(oggpack_writeclear
) "";
18 FDEF(oggpack_look
) "";
19 FDEF(oggpack_look1
) "";
21 FDEF(oggpack_bytes
) "";
22 FDEF(oggpack_bits
) "";
24 FDEF(oggpack_read
) "Return the value of n bits";
25 FDEF(oggpack_read1
) "";
27 FDEF(oggpack_adv
) "Advance the read location by n bits";
28 FDEF(oggpack_adv1
) "";
30 FDEF(oggpack_write
) "Write bits to the buffer.\n\n\
31 The first parameterf is an integer from which the bits will be extracted.\n\
32 The second parameter is the number of bits to write (defaults to 32)";
34 PyTypeObject py_oggpack_buffer_type
= {
35 PyObject_HEAD_INIT(NULL
)
38 sizeof(py_oggpack_buffer
),
41 /* Standard Methods */
42 /* (destructor) */ py_oggpack_buffer_dealloc
,
44 /* (getattrfunc) */ py_oggpack_buffer_getattr
,
45 /* (setattrfunc) */ 0,
47 /* (reprfunc) */ py_oggpack_repr
,
63 static PyMethodDef py_oggpack_buffer_methods
[] = {
64 {"reset", py_oggpack_reset
,
65 METH_VARARGS
, py_oggpack_reset_doc
},
66 {"writeclear", py_oggpack_writeclear
,
67 METH_VARARGS
, py_oggpack_writeclear_doc
},
68 {"look", py_oggpack_look
,
69 METH_VARARGS
, py_oggpack_look_doc
},
70 {"look1", py_oggpack_look1
,
71 METH_VARARGS
, py_oggpack_look1_doc
},
72 {"bytes", py_oggpack_bytes
,
73 METH_VARARGS
, py_oggpack_bytes_doc
},
74 {"bits", py_oggpack_bits
,
75 METH_VARARGS
, py_oggpack_bits_doc
},
76 {"read", py_oggpack_read
,
77 METH_VARARGS
, py_oggpack_read_doc
},
78 {"read1", py_oggpack_read1
,
79 METH_VARARGS
, py_oggpack_read1_doc
},
80 {"write", py_oggpack_write
,
81 METH_VARARGS
, py_oggpack_write_doc
},
82 {"adv", py_oggpack_adv
,
83 METH_VARARGS
, py_oggpack_adv_doc
},
84 {"adv1", py_oggpack_adv1
,
85 METH_VARARGS
, py_oggpack_adv1_doc
},
90 py_oggpack_buffer_dealloc(PyObject
*self
)
96 py_oggpack_buffer_getattr(PyObject
*self
, char *name
)
98 return Py_FindMethod(py_oggpack_buffer_methods
, self
, name
);
102 py_oggpack_buffer_new(PyObject
*self
, PyObject
*args
)
104 py_oggpack_buffer
*ret
;
106 if (!PyArg_ParseTuple(args
, ""))
109 ret
= (py_oggpack_buffer
*) PyObject_NEW(py_oggpack_buffer
,
110 &py_oggpack_buffer_type
);
114 oggpack_writeinit(&ret
->ob
);
115 return (PyObject
*)ret
;
119 py_oggpack_reset(PyObject
*self
, PyObject
*args
)
121 if (!PyArg_ParseTuple(args
, ""))
124 oggpack_reset(PY_OGGPACK_BUFF(self
));
130 py_oggpack_writeclear(PyObject
*self
, PyObject
*args
)
132 if (!PyArg_ParseTuple(args
, ""))
135 oggpack_writeclear(PY_OGGPACK_BUFF(self
));
141 py_oggpack_look(PyObject
*self
, PyObject
*args
)
145 if (!PyArg_ParseTuple(args
, "l", &bits
))
149 PyErr_SetString(PyExc_ValueError
, "Cannot look at more than 32 bits");
153 ret
= oggpack_look(PY_OGGPACK_BUFF(self
), bits
);
154 return PyLong_FromLong(ret
);
158 py_oggpack_look1(PyObject
*self
, PyObject
*args
)
162 if (!PyArg_ParseTuple(args
, ""))
165 ret
= oggpack_look1(PY_OGGPACK_BUFF(self
));
166 return PyLong_FromLong(ret
);
170 py_oggpack_bytes(PyObject
*self
, PyObject
*args
)
174 if (!PyArg_ParseTuple(args
, ""))
177 ret
= oggpack_bytes(PY_OGGPACK_BUFF(self
));
178 return PyLong_FromLong(ret
);
182 py_oggpack_bits(PyObject
*self
, PyObject
*args
)
186 if (!PyArg_ParseTuple(args
, ""))
189 ret
= oggpack_bits(PY_OGGPACK_BUFF(self
));
190 return PyLong_FromLong(ret
);
194 py_oggpack_write(PyObject
*self
, PyObject
*args
)
199 if (!PyArg_ParseTuple(args
, "l|l", &val
, &bits
))
203 PyErr_SetString(PyExc_ValueError
, "Cannot write more than 32 bits");
207 oggpack_write(PY_OGGPACK_BUFF(self
), val
, bits
);
214 py_oggpack_read(PyObject
*self
, PyObject
*args
)
219 if (!PyArg_ParseTuple(args
, "|i", &bits
))
223 PyErr_SetString(PyExc_ValueError
, "Cannot read more than 32 bits");
227 ret
= oggpack_read(PY_OGGPACK_BUFF(self
), bits
);
229 return PyInt_FromLong(ret
);
233 py_oggpack_read1(PyObject
*self
, PyObject
*args
)
237 if (!PyArg_ParseTuple(args
, ""))
240 ret
= oggpack_read1(PY_OGGPACK_BUFF(self
));
241 return PyInt_FromLong(ret
);
245 py_oggpack_adv(PyObject
*self
, PyObject
*args
)
249 if (!PyArg_ParseTuple(args
, "i", &bits
))
252 oggpack_adv(PY_OGGPACK_BUFF(self
), bits
);
259 py_oggpack_adv1(PyObject
*self
, PyObject
*args
)
261 if (!PyArg_ParseTuple(args
, ""))
264 oggpack_adv1(PY_OGGPACK_BUFF(self
));
270 py_oggpack_repr(PyObject
*self
)
272 oggpack_buffer
*ob
= PY_OGGPACK_BUFF(self
);
275 sprintf(buf
, "<OggPackBuff, endbyte = %ld, endbit = %d at %p>", ob
->endbyte
,
277 return PyString_FromString(buf
);