2007-07-13 13:40:04 +00:00
|
|
|
#ifndef FILE_SNAPSHOT_H
|
|
|
|
#define FILE_SNAPSHOT_H
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
struct snapshot
|
|
|
|
{
|
2007-07-13 13:40:04 +00:00
|
|
|
int data_size;
|
2007-05-22 15:03:32 +00:00
|
|
|
int num_items;
|
2007-07-13 13:40:04 +00:00
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
struct item
|
|
|
|
{
|
|
|
|
int type_and_id;
|
2007-07-13 13:40:04 +00:00
|
|
|
|
|
|
|
int *data() { return (int *)(this+1); }
|
2007-05-22 15:03:32 +00:00
|
|
|
int type() { return type_and_id>>16; }
|
|
|
|
int id() { return type_and_id&(0xffff); }
|
2007-07-13 13:40:04 +00:00
|
|
|
int key() { return type_and_id; }
|
2007-05-22 15:03:32 +00:00
|
|
|
};
|
2007-07-13 13:40:04 +00:00
|
|
|
|
|
|
|
int *offsets() { return (int *)(this+1); }
|
|
|
|
char *data_start() { return (char *)(offsets() + num_items); }
|
|
|
|
item *get_item(int index) { return (item *)(data_start() + offsets()[index]); };
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-07-13 13:40:04 +00:00
|
|
|
// returns the number of ints in the item data
|
|
|
|
int get_item_datasize(int index)
|
|
|
|
{
|
|
|
|
if(index == num_items-1)
|
|
|
|
return (data_size - offsets()[index]) - sizeof(item);
|
|
|
|
return (offsets()[index+1] - offsets()[index]) - sizeof(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_item_index(int key)
|
|
|
|
{
|
|
|
|
// TODO: this should not be a linear search. very bad
|
|
|
|
for(int i = 0; i < num_items; i++)
|
|
|
|
{
|
|
|
|
if(get_item(i)->key() == key)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2007-05-22 15:03:32 +00:00
|
|
|
};
|
|
|
|
|
2007-07-13 13:40:04 +00:00
|
|
|
void *snapshot_empty_delta();
|
|
|
|
int snapshot_create_delta(snapshot *from, snapshot *to, void *data);
|
|
|
|
int snapshot_unpack_delta(snapshot *from, snapshot *to, void *data, int data_size);
|
|
|
|
|
|
|
|
#endif // FILE_SNAPSHOT_H
|