xdrgen is a code generator that takes XDR IDL files (.x files) as specified
in RFC 4506 and provides the AST to
code generators. It is intended to be used as a library with custom generators.
xdrgen requires ruby 3.1 to 3.3 to run.
Xdrgen is a relatively stable library and major changes have not been made to it for sometime.
Aside from the test fixtures in spec/fixtures, the only .x files that have been tested with it are the .x files used for the Stellar protocol.
Note
Generators are no longer maintained in this repository.
If you're building a code generator, use xdrgen as a library (see below).
Generators that were previously included (Python, Java, Rust) have been moved out to other repositories close to the Stellar XDR libraries they generated. This happened in #226 and #221.
For any that were not moved but deleted (C#, Elixir, Ruby), they can be found in the repository history at commit 2efacde if they need to be used with the binary, otherwise any new maintenance of code generators should happen using xdrgen as a library.
The JavaScript and Go generators still live here at this time.
Add this line to your application's Gemfile:
gem 'xdrgen'And then execute:
$ bundle
Example usage:
require 'xdrgen'
class Generator < Xdrgen::Generators::Base
def generate
out = @output.open("#{@namespace}.rs")
# Use @top to access the top of the AST.
# Use @options to access any options passed via the compile.
# Use out.puts to write code.
end
end
Xdrgen::Compilation.new(
["MyProgram.x"],
output_dir:"src/generated",
generator: Generator,
namespace: "MyProgram::XDR",
options: { }, # any option your generator needs
).compileXdrgen is a rubygem, compatible with ruby 2.1 or higher
$ gem install xdrgen
The command line:
xdrgen [-o OUTPUT_DIR] [-l LANGUAGE] [-n NAMESPACE] [INPUT_FILES ...]
The CLI still has the following built-in generators:
- javascript
- golang