mix flatbuf.gen (flatbuf v0.1.0)

Copy Markdown View Source

Generate Elixir modules from one or more FlatBuffers .fbs files.

mix flatbuf.gen SCHEMA.fbs [SCHEMA.fbs ...] [--out PATH] [--wire-module NAME]
                           [--namespace NAME] [--include PATH]
                           [--niceties PROTO,PROTO ...]
                           [--force]

Each schema is parsed and resolved, then turned into a set of .ex files written under --out (default lib/). The Wire helper module is shared across all generated tables for the run; pass --wire-module to control its name (default Flatbuf.Generated.Wire).

Options

  • --out PATH — output directory (default lib).
  • --wire-module NAME — module name for the emitted wire helper.
  • --namespace NAME — replace the .fbs file's namespace declaration when naming Elixir modules. Useful for vendoring an upstream schema (e.g. Apache Arrow) under your project's own namespace tree. Every generated module's name becomes NAME.<short_name>, regardless of what the schema declared.
  • --include PATH — additional directory to search for include files (the schema's own directory is always searched first). Repeatable.
  • --niceties LIST — comma-separated opt-in protocols/behaviours to wire into generated tables. Currently supported: behaviour (implements Flatbuf.Table), jason (derives Jason.Encoder). Unknown names abort the task.
  • --force — overwrite outputs even when their content is unchanged.

Nicety dependency caveats

Niceties add references the consumer project must satisfy:

  • jason — the generated @derive Jason.Encoder only compiles if your project depends on :jason. Add {:jason, "~> 1.4"} to your deps before enabling it.
  • behaviour — the generated @behaviour Flatbuf.Table needs :flatbuf available when the generated code compiles. If you depend on :flatbuf with only: [:dev, :test], prod compiles will warn that the Flatbuf.Table behaviour is undefined (a hard failure under --warnings-as-errors). Use a regular dependency if you enable this nicety.