Skip to content

Instantly share code, notes, and snippets.

@blackball
Created November 8, 2011 12:37
Show Gist options
  • Save blackball/1347646 to your computer and use it in GitHub Desktop.
Save blackball/1347646 to your computer and use it in GitHub Desktop.
int pack_arr(struct db *dbase, void *data, int len)
{
int code = -1;
struct db_node *node = new_node(len);
memcpy(node->data, data, len);
// insert node into dbase
dump(dbase, node);
code = 0;
return code;
}
/**
* unpack a array data from database
*
* @param dbase database handle
* @param data array
* @param len sizeof(type)*n
* @param idx -1 for continious, [0, len-1] for idx
*
* @return
*/
int unpack_arr(struct db* dbase, void *data, int len, int idx)
{
int code = -1;
struct db_node *node = undump(dbase, idx);
if (node != NULL)
{
memcpy(data,node->data,len);
code = 0;
}
return code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment