7. Save related circuits¶
Save the shared vtree once and each circuit separately. In this example the two circuits are backup rules: local or remote storage, and remote implies encryption.
7.1. Serialize¶
The API returns owned text and byte buffers. Write the vtree text and each
buffer to your preferred files or storage; use tididi_bytes_data and
tididi_bytes_len to obtain the bytes. Serialization borrows the circuits.
char *vtree_text = NULL;
TididiBytes *first = NULL, *second = NULL;
check(tididi_vtree_to_text(vtree, &vtree_text));
check(tididi_to_bytes(destination, &first));
check(tididi_to_bytes(encryption, &second));
7.2. Restore one shared domain¶
Parse the vtree once, then load both circuits onto that same handle. They can then be combined immediately.
TididiVtree *restored = NULL;
TididiCircuit *left = NULL, *right = NULL, *rules = NULL;
check(tididi_vtree_from_text(vtree_text, &restored));
check(tididi_from_bytes(restored, tididi_bytes_data(first), tididi_bytes_len(first), &left));
check(tididi_from_bytes(restored, tididi_bytes_data(second), tididi_bytes_len(second), &right));
check(tididi_and(left, right, &rules, NULL));
printf("Restored valid configurations: %" PRIu64 "\n", count(rules));
Output:
Restored valid configurations: 4
7.3. Complete program¶
Download persistence.c and the
shared helper. The source includes cleanup
for all handles. Both files are included in the source checkout.