Yrs C foreign function interface
This project is a wrapper around Yrs and targets native interop with possible host languages.
It's a library used on collaborative document editing using Conflict-free Replicated Data Types.
This enables to provide a shared document editing experience on a client devices without explicit requirement for hosting a single server - CRDTs can resolve potential update conflicts on their own with no central authority - as well as provide first-class offline editing capabilities, where document replicas are modified without having connection to each other, and then synchronize automatically once such connection is enabled.
It's also possible to read it straight from a generated C header file.
Example
#include <stdio.h>
#include "libyrs.h"
int main(void) {
YDoc* doc = ydoc_new();
YTransaction* txn = ytransaction_new(doc);
YText* txt = ytext(txn, "name");
ytext_insert(txt1, t1, 0, "hello world");
YDoc* remote_doc = ydoc_new();
YTransaction* remote_txn = ytransaction_new(remote_doc);
YText* remote_txt = ytext(remote_txn, "name");
int sv_length = 0;
unsigned char* remote_sv = ytransaction_state_vector_v1(remote_txn, &sv_length);
int update_length = 0;
unsigned char* update = ytransaction_state_diff_v1(txn, remote_sv, sv_length, &update_length);
ybinary_destroy(remote_sv, sv_length);
ytext_destroy(txt);
ytransaction_commit(txn);
ydoc_destroy(doc);
ytransaction_apply(remote_txn, update, update_length);
ybinary_destroy(update, update_length);
char* str = ytext_string(remote_txt, remote_txn);
printf("%s", str);
ystring_destroy(str);
ytext_destroy(remote_txt);
ytransaction_commit(remote_txn);
ydoc_destroy(remote_doc);
return 0;
}