Skip to content

Commit 82b18a6

Browse files
docs(examples): make clear the CBOR ABI is for IPC only
Every generated library exports both ABIs side by side; spell out the choice in the example READMEs: the native (pure-C) ABI is the default for same-process / local calls (flat C structs, zero serialization), while the CBOR ABI exists solely for inter-process communication (different process or machine). In a shared address space CBOR is pure overhead, so prefer native locally. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 525dfbc commit 82b18a6

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

examples/timer/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
This example is a self-contained Nimble project demonstrating how to import `nim-ffi` and use the `.ffiCtor.` / `.ffi.` abstraction.
44

5+
## Two ABIs, one library
6+
7+
Every generated library exports **two ABIs side by side**, and you choose per call site:
8+
9+
| ABI | Header / symbols | Use it for |
10+
|-----|------------------|------------|
11+
| **Native (pure C)** | `<lib>.h` / `<name>` | **Same-process / local** calls. Flat C structs by value, zero serialization. |
12+
| **CBOR** | `<lib>_cbor.h` / `<name>_cbor` | **Inter-process communication only** — a different process or machine, where the request must be serialized to cross the boundary. |
13+
14+
In a shared address space the CBOR round-trip is pure overhead, so **default to the native ABI locally and reach for CBOR only when you actually cross a process/machine boundary** (see [`ipc/`](ipc)). The per-language examples below: native C ([`c_bindings/`](c_bindings)), native Go ([`go_bindings/`](go_bindings)), native/CBOR C++ ([`cpp_bindings/`](cpp_bindings)), CBOR Rust ([`rust_client/`](rust_client)), and CBOR-over-socket IPC ([`ipc/`](ipc)).
15+
516
## Usage
617

718
1. Change into the example directory:

examples/timer/c_bindings/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
Generated C headers for the timer library plus a small driver that links the
44
library directly and calls the **native** (zero-serialization) ABI.
55

6+
> **Which ABI?** The library exports **both** ABIs from the same shared object,
7+
> side by side: the native `<name>` symbols and the CBOR `<name>_cbor` symbols.
8+
> Use the **native (pure-C) ABI for same-process / local calls** — it passes
9+
> flat C structs with zero serialization. Use the **CBOR ABI only for
10+
> inter-process communication** (a different process, or a different machine),
11+
> where the data has to be serialized to cross the boundary anyway. In one
12+
> address space, CBOR is pure overhead — prefer native. See [`../ipc`](../ipc)
13+
> for the CBOR/IPC path.
14+
615
## Files
716

817
| File | Description |

examples/timer/ipc/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ library **in the same process**. When the caller lives in a *different process*
66
request has to be serialized. That is exactly what the **CBOR ABI**
77
(`<name>_cbor`, declared in `my_timer_cbor.h`) is for.
88

9+
> **The CBOR ABI exists solely for inter-process communication.** If you are in
10+
> the same process as the library, use the native ABI instead — serializing to
11+
> CBOR and decoding it on a sibling thread is pure overhead when you already
12+
> share memory. Both ABIs ship in the same library; pick per call site.
13+
914
This example wires that ABI across a socket:
1015

1116
- **`server`** links `libmy_timer`, creates one timer context at startup, and

0 commit comments

Comments
 (0)