Browse Source

Make append_binary signature look like append_string

tags/nilmdb-1.5.0
Jim Paris 11 years ago
parent
commit
d9afb48f45
1 changed files with 30 additions and 15 deletions
  1. +30
    -15
      nilmdb/server/rocket.c

+ 30
- 15
nilmdb/server/rocket.c View File

@@ -423,29 +423,37 @@ extra_data_on_line:
* Append from binary data
*/

/* .append_binary(self, data, start, end, last_timestamp) */
/* .append_binary(count, data, offset, linenum, start, end, last_timestamp) */
static PyObject *Rocket_append_binary(Rocket *self, PyObject *args)
{
int count;
const uint8_t *data;
int data_len;
int linenum;
int offset;
timestamp_t start;
timestamp_t end;
timestamp_t last_timestamp;

if (!PyArg_ParseTuple(args, "t#lll:append_binary",
&data, &data_len,
&start, &end, &last_timestamp))
if (!PyArg_ParseTuple(args, "it#iilll:append_binary",
&count, &data, &data_len, &offset,
&linenum, &start, &end, &last_timestamp))
return NULL;

/* Check data length */
if (data_len % self->binary_size != 0)
return raise_str(0, 0, ERR_OTHER, "data size must be a "
"multiple of binary record size");
/* Advance to offset */
if (offset > data_len)
return raise_str(0, 0, ERR_OTHER, "bad offset");
data += offset;
data_len -= offset;

/* Figure out max number of rows to insert */
int rows = data_len / self->binary_size;
if (rows > count)
rows = count;

/* Check timestamps */
timestamp_t ts;
int i;
int rows = data_len / self->binary_size;
for (i = 0; i < rows; i++) {
/* Read raw timestamp, byteswap if needed */
memcpy(&ts, &data[i * self->binary_size], 8);
@@ -468,7 +476,8 @@ static PyObject *Rocket_append_binary(Rocket *self, PyObject *args)

/* Build return value and return */
PyObject *o;
o = Py_BuildValue("(il)", rows, last_timestamp);
o = Py_BuildValue("(iili)", rows, offset + rows * self->binary_size,
last_timestamp, linenum);
return o;
}

@@ -685,17 +694,21 @@ static PyMethodDef Rocket_methods[] = {
"Raises ParseError if timestamps are non-monotonic, outside\n"
"the start/end interval etc.\n"
"\n"
"On success, return a tuple with three values:\n"
"On success, return a tuple:\n"
" added_rows: how many rows were added from the file\n"
" data_offset: current offset into the data string\n"
" last_timestamp: last timestamp we parsed" },
" last_timestamp: last timestamp we parsed\n"
" linenum: current line number" },

{ "append_binary",
(PyCFunction)Rocket_append_binary, METH_VARARGS,
"append_binary(self, data, start, end, ts)\n\n"
"append_binary(self, count, data, offset, line, start, end, ts)\n\n"
"Append binary data, which must match the data layout.\n"
"\n"
" count: maximum number of rows to add\n"
" data: binary data\n"
" offset: byte offset into data to start adding\n"
" line: current line number (unused)\n"
" start: starting timestamp for interval\n"
" end: end timestamp for interval\n"
" ts: last timestamp that was previously parsed\n"
@@ -703,9 +716,11 @@ static PyMethodDef Rocket_methods[] = {
"Raises ParseError if timestamps are non-monotonic, outside\n"
"the start/end interval etc.\n"
"\n"
"On success, return a tuple with two values:\n"
"On success, return a tuple:\n"
" added_rows: how many rows were added from the file\n"
" last_timestamp: last timestamp we parsed" },
" data_offset: current offset into the data string\n"
" last_timestamp: last timestamp we parsed\n"
" linenum: current line number (copied from argument)" },

{ "extract_string",
(PyCFunction)Rocket_extract_string, METH_VARARGS,


Loading…
Cancel
Save