feat(ffi): native event delivery + dual-ABI event symbols (C + Go)#62
Draft
Ivansete-status wants to merge 3 commits into
Draft
feat(ffi): native event delivery + dual-ABI event symbols (C + Go)#62Ivansete-status wants to merge 3 commits into
Ivansete-status wants to merge 3 commits into
Conversation
Events now mirror the native/CBOR split already in place for requests, with the
same symbol-naming convention:
- `<lib>_add_event_listener` -> NATIVE listener (typed `<T>Pod` by pointer)
- `<lib>_add_event_listener_cbor` -> CBOR listener (EventEnvelope bytes)
Framework: `FFIEventListener` gains a `native` flag; `addEventListener` a
`native` param; a new `dispatchFFIEventDual` template builds the `<T>Pod` once
for native listeners (`nimToPod`/`freePod`) and the CBOR envelope once for the
rest, fanning each out — so a single `{.ffiEvent.}` dispatch serves both kinds.
`declareLibrary` exports both registration entry points.
Generators: the bare `<lib>_add_event_listener` is the native symbol; every
CBOR consumer (C/C++/Go/Rust) now targets `<lib>_add_event_listener_cbor`. The
rename and the generator updates ship together so the bare name is never briefly
broken. Bindings regenerated.
Validated: native-event unit test (typed POD to native + CBOR to cbor listener,
orc/refc/ASAN); full unit suite; C++ e2e 19/19; Go example; existing event
tests unchanged. The per-event *typed* native callback + wildcard router (the
ergonomic consumer surface) is a follow-up.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds the ergonomic native event surface for Go: `node.On<Event>(func(<Payload>))` registers a native listener for that event and the library delivers the typed `<Payload>` POD, which an exported Go callback reads into a Go struct (reusing the generated `fromC`) and hands to the user's handler — no CBOR parsing. Sits beside the existing CBOR `SetEventHandler` (wildcard / inter-process). The example registers `OnEchoFired` and receives a typed `EchoEvent` when Echo fires it. Verified end-to-end with `go run -race`. C/C++/Rust get the same per-event typed handler + router next. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…) + tasks - Add the `-d:ffiMode=native|cbor|both` strdefine (default both) with `ffiEmitNative`/`ffiEmitCbor` helpers; the C generator now emits only the selected header(s) (`<lib>.h` and/or `<lib>_cbor.h`). - Native C events: the native header documents each event's payload type (`"on_echo_fired" -> const EchoEvent *`) so consumers cast the callback's msg to the typed struct — the bare native listener already delivers it. - nimble tasks: `genbindings_c` (both), `genbindings_c_native`, `genbindings_c_cbor`. Verified: native mode emits only my_timer.h, cbor only my_timer_cbor.h, both emits both. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced May 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Foundation for emitting both the native (zero-serialization C-POD) and CBOR ABIs side-by-side for
{.ffiEvent.}events, completing the request-side dual ABI from the earlier PRs in this stack.{.ffiEvent.}declaration now fires both a native typed-POD listener and a CBOR listener from a single dispatch. Native listeners get the payload built once vianimToPod/freePod; CBOR is serialized once for the rest.<lib>_add_event_listeneris native,<lib>_add_event_listener_cboris CBOR.-d:ffiMode=native|cbor|bothstrdefine (defaultboth) gates which ABI each generator emits, withgenbindings_*_native/_cbornimble tasks."on_echo_fired" -> const EchoEvent *) and routes the CBOR header to_add_event_listener_cbor.On<Event>(func(<Payload>))with exported callbacks +fromC.Native is the same-process path; CBOR is IPC-only.
Test
test_native_events,test_native_pod_types, and the C native+CBOR concurrency stress harness pass (ASAN/TSAN clean).🤖 Generated with Claude Code