Command line flags
--input
Specifies the input CDDL file(s).
For a single file:
cddl-codegen --input examples/test.cddl --output export
If a directory is specified e.g. --input=some_dir
then it will read all files in this directory (non-recursively).
The output format changes here. If there's a lib.cddl
the types contained there are the standard output , and any other file e.g. foo.cddl
will have its own module foo/mod.rs
with its own foo/serialization.rs
, etc.
cddl-codegen --input examples --output export
--output
Specifies the output directory.
cddl-codegen --input examples --output export
--lib-name
Specify the rust crate name for the output library. The wasm crate will have -wasm
appended.
cddl-codegen --input=example --output=export --lib-name some-crate-name
--to-from-bytes-methods
Generates to_cbor_bytes()
/ from_cbor_bytes()
methods on all WASM objects. On by default.
(The rust code doesn't need this as you can directly use the Serialize
/Deserialize
traits on them.)
Possible values: true, false
cddl-codegen --input=example --output=export --to-from-bytes-methods true
--wasm
Whether to output a wasm crate. On by default.
Possible values: true, false
cddl-codegen --input=example --output=export --wasm false
--preserve-encodings
Preserves CBOR encoding upon deserialization e.g. definite vs indefinite, map ordering. For each module this will also create a cbor_encodings.rs
file to potentially store any structs for storing these encodings. This option is useful if you need to preserve the deserialized format for round-tripping (e.g. hashes) or if you want to modify the format to coincide with a specific tool for hashing.
Possible values: true, false
cddl-codegen --input=example --output=export --preserve-encodings true
--canonical-form
Used primarily with --preserve-encodings
to provide a way to override the specific deserialization format and to instead output canonical CBOR. This will have Serialize
's trait have an extra to_canonical_cbor_bytes()
method. Likewise the wasm wrappers (with --to-from-bytes-methods
) will contain one too.
Possible values: true, false
cddl-codegen --input=example --output=export --canonical-form true
--json-serde-derives
Derives serde::Serialize/serde::Deserialize for types to allow to/from JSON
Possible values: true, false
cddl-codegen --input=example --output=export --json-serde-derives true
--json-schema-export
Tags types with sonSchema derives and generates a crate (in wasm/json-gen) to export them. This requires --json-serde-derives
.
Possible values: true, false
Default: true
Example:
cddl-codegen --input=example --output=export --json-schema-export true
--package-json
Generates a npm package.json along with build scripts (some of these scripts require --json-serde-derives
/--json-schema-export
to work).
Possible values: true, false
Default: false
cddl-codegen --input=example --output=export --package-json true --json-schema-export true
--common-import-override
Overrides the location of the static exports (e.g. error.rs, serialization.rs, etc).
This is particularly useful for combining multiple crates each generated using cddl-codegen where they all share a shared core directory where the static files are located.
Default: crate
cddl-codegen --input=example --output=export --common-import-override=cml_core
--wasm-cbor-json-api-macro
If it is passed in, it will call the supplied externally defined macro on each exported type, instead of manually exporting the functions for to/from CBOR bytes + to/from JSON API.
The external macro is assumed to exist at the specified path and will be imported if there are module prefixes.
The macro must take the wasm wrapper type as the only parameter.
This macro will be called regardless of the values of to-from-bytes-methods / json-serde-derives / etc, so it is assumed that whatever logic your macros have is consistent with the other CLI flag values.
cddl-codegen --input=example --output=export --wasm-cbor-json-api-macro=cml_core_wasm::impl_wasm_cbor_json_api
--wasm-conversion-macro
If it is passed in, it will call the supplied externally defined macro on each exported type, instead of manually exporting the rust/wasm conversion traits.
The external macro is assumed to exist at the specified path and will be imported if there are module prefixes.
The macro must take the rust type as the first parameter and the wasm wrapper type as the second one.
cddl-codegen --input=example --output=export --wasm-conversion-macro=cml_core_wasm::impl_wasm_conversions