+
+/* 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));
+ }
+ }
+}