mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-20 16:29:31 +00:00
The Go generator previously emitted a `// SKIPPED` stub for any proc with a
struct, sequence or optional parameter, leaving Echo/Complex/Schedule
uncallable. Now that the native ABI carries those as flat C-POD structs, the Go
side can marshal them: emit an idiomatic Go struct per {.ffi.} type plus a
`toC()` that builds the matching `C.<Type>` (C.CString for strings, a C array
for seqs, present-flags for options, recursively for nested structs) and
returns cleanup funcs run via defer once the call returns. The native path
deep-copies every argument, so releasing the C buffers immediately is safe.
The C bridge already accepted struct-by-value params via the pass-through type
mapping; only the Go-side conversion and the `allSupported` gate needed work.
Bare seq/Option *top-level* params (not wrapped in a struct) remain skipped, as
the native ABI does not expose them either.
The generated package is now self-contained: the native `<lib>.h` is emitted
beside the `.go`, and the cgo directives use ${SRCDIR} so the header and the
staged library resolve without extra env vars. genbindings_go runs gofmt to
finalize column alignment.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
116 lines
2.7 KiB
C
116 lines
2.7 KiB
C
// Generated by nim-ffi C codegen. Do not edit by hand.
|
|
//
|
|
// Native (zero-serialization) C ABI. Each call delivers its result to the
|
|
// callback: on RET_OK, (msg, len) is the raw return value (for string-returning
|
|
// procs, the string bytes — not NUL-terminated; use len); on RET_ERR, (msg, len)
|
|
// is the raw error text. A `<name>_cbor` variant of each proc also exists for
|
|
// generic/cross-language callers that prefer a CBOR request/response.
|
|
#ifndef NIM_FFI_GEN_MY_TIMER_H
|
|
#define NIM_FFI_GEN_MY_TIMER_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifndef NIM_FFI_RET_CODES
|
|
#define NIM_FFI_RET_CODES
|
|
#define RET_OK 0
|
|
#define RET_ERR 1
|
|
#define RET_MISSING_CALLBACK 2
|
|
#endif
|
|
|
|
#ifndef NIM_FFI_CALLBACK_T
|
|
#define NIM_FFI_CALLBACK_T
|
|
typedef void (*FFICallBack)(int callerRet, const char *msg, size_t len, void *userData);
|
|
#endif
|
|
|
|
|
|
// --- {.ffi.}-annotated types, exposed as C structs ----------
|
|
typedef struct {
|
|
const char* name;
|
|
} TimerConfig;
|
|
|
|
typedef struct {
|
|
const char* message;
|
|
int64_t delayMs;
|
|
} EchoRequest;
|
|
|
|
typedef struct {
|
|
const char* echoed;
|
|
const char* timerName;
|
|
} EchoResponse;
|
|
|
|
typedef struct {
|
|
EchoRequest *messages;
|
|
size_t messages_len;
|
|
const char* *tags;
|
|
size_t tags_len;
|
|
int note_present;
|
|
const char* note;
|
|
int retries_present;
|
|
int64_t retries;
|
|
} ComplexRequest;
|
|
|
|
typedef struct {
|
|
const char* summary;
|
|
int64_t itemCount;
|
|
int hasNote;
|
|
} ComplexResponse;
|
|
|
|
typedef struct {
|
|
const char* message;
|
|
int64_t echoCount;
|
|
} EchoEvent;
|
|
|
|
typedef struct {
|
|
const char* name;
|
|
const char* *payload;
|
|
size_t payload_len;
|
|
int64_t priority;
|
|
} JobSpec;
|
|
|
|
typedef struct {
|
|
int64_t maxAttempts;
|
|
int64_t backoffMs;
|
|
const char* *retryOn;
|
|
size_t retryOn_len;
|
|
} RetryPolicy;
|
|
|
|
typedef struct {
|
|
int64_t startAtMs;
|
|
int64_t intervalMs;
|
|
int jitter_present;
|
|
int64_t jitter;
|
|
} ScheduleConfig;
|
|
|
|
typedef struct {
|
|
const char* jobId;
|
|
int64_t willRunCount;
|
|
int64_t firstRunAtMs;
|
|
int64_t effectiveBackoffMs;
|
|
} ScheduleResult;
|
|
|
|
|
|
void *my_timer_create(TimerConfig config, FFICallBack callback, void *userData);
|
|
|
|
int my_timer_echo(void *ctx, FFICallBack callback, void *userData, EchoRequest req);
|
|
|
|
int my_timer_version(void *ctx, FFICallBack callback, void *userData);
|
|
|
|
int my_timer_complex(void *ctx, FFICallBack callback, void *userData, ComplexRequest req);
|
|
|
|
int my_timer_schedule(void *ctx, FFICallBack callback, void *userData, JobSpec job, RetryPolicy retry, ScheduleConfig schedule);
|
|
|
|
int my_timer_destroy(void *ctx);
|
|
|
|
uint64_t my_timer_add_event_listener(void *ctx, const char *eventName, FFICallBack callback, void *userData);
|
|
int my_timer_remove_event_listener(void *ctx, uint64_t listenerId);
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif
|
|
|
|
#endif /* NIM_FFI_GEN_MY_TIMER_H */ |