11
2- // Generated manually and inspired by the one generated by the Nim Compiler.
3- // In order to see the header file generated by Nim just run `make libsds`
4- // from the root repo folder and the header should be created in
5- // nimcache/release/libsds/libsds.h
2+ // C API for libsds, built on the nim-ffi framework.
3+ //
4+ // Parameters and results are marshalled as JSON: each request/response struct
5+ // in library/libsds.nim is a JSON object, passed in via the `*Json` cstring
6+ // argument and returned to the callback as a JSON string. Binary fields
7+ // (message bytes) are JSON arrays of byte values.
68#ifndef __libsds__
79#define __libsds__
810
1820extern "C" {
1921#endif
2022
23+ // Result/event callback. `msg` is the (JSON) payload of length `len`.
24+ // callerRet is one of the RET_* codes above.
2125typedef void (* SdsCallBack ) (int callerRet , const char * msg , size_t len , void * userData );
2226
27+ // Synchronous provider invoked by SDS-R to fetch a retrieval hint for a
28+ // message id. The implementation allocates `*hint` (and sets `*hintLen`); the
29+ // library takes ownership and frees it with deallocShared.
2330typedef void (* SdsRetrievalHintProvider ) (const char * messageId , char * * hint , size_t * hintLen , void * userData );
2431
2532
2633// --- Core API Functions ---
2734
2835
29- void * SdsNewReliabilityManager (SdsCallBack callback , void * userData );
36+ // Create a context + ReliabilityManager. configJson: {"participantId":"..."}
37+ // (empty participantId disables SDS-R). Returns the context handle, or NULL on
38+ // failure. The callback also fires on async completion.
39+ void * sds_create (const char * configJson , SdsCallBack callback , void * userData );
3040
31- void SdsSetEventCallback (void * ctx , SdsCallBack callback , void * userData );
41+ // Register the event callback (message_ready, message_sent,
42+ // missing_dependencies, periodic_sync, repair_ready). Payloads are JSON.
43+ void sds_set_event_callback (void * ctx , SdsCallBack callback , void * userData );
3244
33- void SdsSetRetrievalHintProvider (void * ctx , SdsRetrievalHintProvider callback , void * userData );
45+ // Register the retrieval-hint provider used by SDS-R.
46+ int sds_set_retrieval_hint_provider (void * ctx , SdsRetrievalHintProvider callback , void * userData );
3447
35- int SdsCleanupReliabilityManager (void * ctx , SdsCallBack callback , void * userData );
48+ // reqJson: {"message":[..bytes..],"messageId":"..","channelId":".."}
49+ // Result JSON: {"message":[..bytes..]}
50+ int sds_wrap_outgoing_message (void * ctx , SdsCallBack callback , void * userData , const char * reqJson );
3651
37- int SdsResetReliabilityManager (void * ctx , SdsCallBack callback , void * userData );
52+ // reqJson: {"message":[..bytes..]}
53+ // Result JSON: {"message":[..],"channelId":"..","missingDeps":[{"messageId":"..","retrievalHint":"<base64>"}]}
54+ int sds_unwrap_received_message (void * ctx , SdsCallBack callback , void * userData , const char * reqJson );
3855
39- int SdsWrapOutgoingMessage (void * ctx ,
40- void * message ,
41- size_t messageLen ,
42- const char * messageId ,
43- const char * channelId ,
44- SdsCallBack callback ,
45- void * userData );
56+ // reqJson: {"messageIds":["..",".."],"channelId":".."}
57+ int sds_mark_dependencies_met (void * ctx , SdsCallBack callback , void * userData , const char * reqJson );
4658
47- int SdsUnwrapReceivedMessage (void * ctx ,
48- void * message ,
49- size_t messageLen ,
50- SdsCallBack callback ,
51- void * userData );
59+ int sds_reset (void * ctx , SdsCallBack callback , void * userData );
5260
53- int SdsMarkDependenciesMet (void * ctx ,
54- char * * messageIDs ,
55- size_t count ,
56- const char * channelId ,
57- SdsCallBack callback ,
58- void * userData );
59-
60- int SdsStartPeriodicTasks (void * ctx , SdsCallBack callback , void * userData );
61+ int sds_start_periodic_tasks (void * ctx , SdsCallBack callback , void * userData );
6162
63+ // Tear down the context created by sds_create.
64+ int sds_destroy (void * ctx , SdsCallBack callback , void * userData );
6265
6366
6467#ifdef __cplusplus
6568}
6669#endif
6770
68- #endif /* __libsds__ */
71+ #endif /* __libsds__ */
0 commit comments