package wire
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=323f48e6cb897fe48aac558b09bb25134d3b19fec37b20d7930eec15f387c238
sha512=00c77f8672396ab15d993602db9bab95d2478ace1f569606f0140ed25d7ff852525e53436d95e5061442a6ea8b5650549239c68ef861b4b921b4a53faac97eb7
doc/wire.stubs/Wire_stubs/index.html
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):
open Wire
type header = { version : int; length : int }
let codec =
Codec.v "Header"
(fun version length -> { version; length })
Codec.
[
(Field.v "Version" (bits ~width:4 U8) $ fun h -> h.version);
(Field.v "Length" uint16be $ fun h -> h.length);
]
let run () =
Wire_stubs.generate ~schema_dir:"schemas" ~outdir:"."
[ Wire_stubs.C 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.
generate ~schema_dir ~outdir codecs writes all FFI artifacts.
val of_structs :
schema_dir:string ->
outdir:string ->
Wire.Everparse.Raw.struct_ list ->
unitSame as generate but takes raw structs directly.
Individual generators
These are the building blocks used by generate. Most users should not need them directly.
Generate C stubs that call the EverParse validators directly.
build_codec_archive ~schema_dir ~archive compiles each generated validator and _Fields plug in schema_dir as its own translation unit and archives them into archive (pass lib<name>.a to consume it from a dune (foreign_archives <name>)). The wire_ffi.c from to_c_stubs includes only the headers and calls the validators across this link, so per-codec shared types stay translation-unit-local and any set of codecs links. test.c and <Name>Wrapper.c are skipped. Requires cc and ar.
Generate OCaml external declarations and record types for all structs.
Generate a standalone OCaml module with parse and parse_k for one struct.
Derive the OCaml snake_case module name from a struct's CamelCase name.
Convert a Wire struct name to the EverParse CamelCase convention.