Module Wire_stubsSource

OCaml FFI stub generation for EverParse-produced C validators.

Wire_stubs generates C stubs and matching OCaml external declarations so OCaml code can call EverParse-generated validators. Each stub stack- allocates the schema's default plug struct (<Name>Fields from Wire_3d), runs the EverParse validator against it, then marshals the populated struct members into an OCaml record. On validation failure, Failure is raised.

Typical usage (in a code-generation executable):

let () =
  Wire_stubs.generate ~schema_dir:"schemas" ~outdir:"." [ C my_codec ]

This writes wire_ffi.c + stubs.ml into outdir. The WIRECTX socket and the <Name>_Fields plug come from Wire_3d; this module is just one particular consumer of that plug.

Sourcetype packed_codec =
  1. | C : _ Wire.Codec.t -> packed_codec
Sourceval generate : schema_dir:string -> outdir:string -> packed_codec list -> unit

generate ~schema_dir ~outdir codecs writes all FFI artifacts.

Sourceval of_structs : schema_dir:string -> outdir:string -> Wire.Everparse.Raw.struct_ list -> unit

Same as generate but takes raw structs directly.

Individual generators

These are the building blocks used by generate. Most users should not need them directly.

Sourceval to_c_stubs : Wire.Everparse.Raw.struct_ list -> string
Sourceval to_ml_stubs : Wire.Everparse.Raw.struct_ list -> string

Generate OCaml external declarations and record types for all structs.

Sourceval to_ml_stub : Wire.Everparse.Raw.struct_ -> string

Generate a standalone OCaml module with parse and parse_k for one struct.

Sourceval to_ml_stub_name : Wire.Everparse.Raw.struct_ -> string

Derive the OCaml snake_case module name from a struct's CamelCase name.

Sourceval everparse_name : string -> string

Convert a Wire struct name to the EverParse CamelCase convention.

Sourceval ml_type_of : 'a Wire.typ -> string

Return the OCaml type name corresponding to a Wire type.