X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fserialize.c;h=792b01a61b5dd4d08a5c67fd1647c7ef5cf19abe;hb=337e1b04c921c92697b74aed630343c86fabfcbd;hp=f90c63a213411bae10e9821190ccab4d8c677f3a;hpb=6732e9143e2c773a8c94947713bc8fc22613f702;p=bluesky.git diff --git a/bluesky/serialize.c b/bluesky/serialize.c index f90c63a..792b01a 100644 --- a/bluesky/serialize.c +++ b/bluesky/serialize.c @@ -152,8 +152,11 @@ BlueSkyCloudLog *bluesky_serialize_inode(BlueSkyInode *inode) /* Deserialize an inode into an in-memory representation. Returns a boolean * indicating whether the deserialization was successful. */ -gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf) +gboolean bluesky_deserialize_inode(BlueSkyInode *inode, BlueSkyCloudLog *item) { + g_assert(item->data != NULL); + const char *buf = item->data->data; + if (bluesky_verbose) { g_log("bluesky/serialize", G_LOG_LEVEL_DEBUG, "Deserializing inode %lld...", (long long)inode->inum); @@ -190,15 +193,14 @@ gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf) g_array_set_size(inode->blocks, (inode->size + BLUESKY_BLOCK_SIZE - 1) / BLUESKY_BLOCK_SIZE); - // TODO -#if 0 + g_assert(inode->blocks->len == item->links->len); for (int i = 0; i < inode->blocks->len; i++) { BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i); b->type = BLUESKY_BLOCK_REF; - b->ref = g_strdup(buf); - buf += strlen(b->ref) + 1; + b->ref = g_array_index(item->links, BlueSkyCloudLog *, i); + bluesky_cloudlog_ref(b->ref); + b->dirty = NULL; } -#endif break; case BLUESKY_DIRECTORY: @@ -242,3 +244,29 @@ gboolean bluesky_deserialize_inode(BlueSkyInode *inode, const gchar *buf) return TRUE; } + +/* Convert an in-memory cloud log item to a more serialized form, suitable + * either for writing to the local journal or the the cloud. */ +void bluesky_serialize_cloudlog(BlueSkyCloudLog *log, + GString *encrypted, // Raw data payload + GString *authenticated, // Block links + GString *writable) // Writable block links +{ + g_string_append_len(encrypted, log->data->data, log->data->len); + for (int i = 0; i < log->links->len; i++) { + BlueSkyCloudLog *ref = g_array_index(log->links, BlueSkyCloudLog *, i); + if (ref != NULL) { + g_string_append_len(authenticated, + (const char *)&ref->id, + sizeof(BlueSkyCloudID)); + // TODO: Fix endianness of output + g_string_append_len(writable, + (const char *)&ref->location, + sizeof(ref->location)); + } else { + BlueSkyCloudID id; + memset(&id, 0, sizeof(id)); + g_string_append_len(authenticated, (const char *)&id, sizeof(id)); + } + } +}