Kaitai Struct Compiler for Elixir.

Compiles .ksy files into Elixir modules that can parse binary data.

Summary

Functions

Compile a .ksy file into an Elixir source code string.

Compile a .ksy file and load the resulting module into the VM. Returns {:ok, module_atom} on success.

Compile a KSY YAML string into Elixir source code (without loading it).

Compile a KSY YAML string and load the resulting module.

Compile one or more .ksy files and write each top-level module as a separate .ex file.

Functions

compile(ksy_path, opts \\ [])

Compile a .ksy file into an Elixir source code string.

Options:

  • :namespace — module namespace prefix to apply to all generated modules
  • :writer — when true, also generate to_binary/1 and to_file/2 on every non-parameterised module. Default false.

compile_and_load(ksy_path, opts \\ [])

Compile a .ksy file and load the resulting module into the VM. Returns {:ok, module_atom} on success.

Options:

  • :namespace — module namespace prefix to apply to all generated modules
  • :writer — when true, also generate to_binary/1 and to_file/2. Default false.

compile_string(yaml_string, opts \\ [])

Compile a KSY YAML string into Elixir source code (without loading it).

Options match compile/2.

compile_string_and_load(yaml_string, opts \\ [])

Compile a KSY YAML string and load the resulting module.

Options:

  • :namespace — module namespace prefix to apply to the generated module
  • :writer — when true, also generate to_binary/1 and to_file/2. Default false.

compile_to_files(input_path, output_dir, opts \\ [])

Compile one or more .ksy files and write each top-level module as a separate .ex file.

  • input_path — a single .ksy file or a directory containing .ksy files
  • output_dir — directory where .ex files are written (created if it doesn't exist)
  • opts — keyword list of options:
    • :namespace — module namespace prefix (default: "Ksc.Compiled")
    • :writer — when true, also generate to_binary/1 + to_file/2. Default false.

Returns {:ok, [written_file_paths]} or {:error, reason}.