jonnify·bcs /bcs/elixir-core/gates/the-native-codec

B2.6.2 · dive 2 of 3 · module B2.6

A native codec with a pure fallback.

EchoData.Native accelerates the hot codec and hash with a Rust core through a C shim; when the NIF is absent the pure Elixir path serves, with identical results. One module routes between them.

BrandedId checks loaded? and routes to the native path or the pure one. Select a part.
BrandedId codecif Native.loaded? loadedEchoData.Native — NIF (Rust + C)decode, decode_hash, encode, hash32 absentpure Elixiridentical results, no native build needed
readout · Select a part. BrandedId owns the codec and checks Native.loaded?; when present, decode/encode/hash32 run in the Rust core; when absent, the pure Elixir path serves with identical results.
§1

The idea

echo_data · native.ex, branded_id.ex

The codec and the hash are the hot path — every id crossing a boundary is parsed, and many are hashed to place a key — so EchoData.Native offers a native core for exactly those operations: decode, decode_hash, encode, and hash32, backed by Rust through a C shim. It is optional: when the shared object is absent, every call falls back to the pure Elixir implementations, so the library runs with or without the native build.

One module owns the codec, and it chooses the path. EchoData.BrandedId checks Native.loaded? and routes to the native function or the pure one, and loaded?/0 reports which is active; everything else — the tries, the maps, the persistence type, the web layer — calls through BrandedId and never sees the difference. The acceleration is a swap behind a single door, not a change to any caller.

Codemojex runs the pure path in development and the native path in production from the same code, and a node’s log records which served. A move is gated and a key is placed at native speed where the build is present, and the game still runs unchanged on a machine where it is not — the hot path made fast where it counts, correct everywhere.

§4

The doors

the sibling courses
§2

References

sources · related

Sources

Related