Skip to main content

Crate canton_lf

Crate canton_lf 

Source
Expand description

Daml-LF archive reader and decoder.

The codegen front-end of the Canton Rust SDK: it reads a .dar and decodes its Daml-LF packages into the AST that canton-codegen lowers to IR and turns into Rust. Most users never call this crate directly — they run canton-codegen-cli (dpm codegen-rust).

  • Dar — the DAR container layer (zip + MANIFEST.MF → the raw Daml-LF bytes of the main package and its dependencies).
  • decode_all / decode_main_package — Daml-LF protobuf decode (LF 2.x → typed AST) with the interned-table resolvers.

The decode is built on the official daml-lf-archive schema: the vendored daml_lf.proto / daml_lf2.proto under proto/ are Digital Asset’s own archive definitions (pinned to a Daml 3.3 snapshot), so the bytes→AST step is machine-generated from the authoritative source rather than hand-written. The interpretation on top (version dispatch, interning, reference resolution) is held to the official JVM daml-lf-archive reader by a conformance oracle: tests/oracle.rs renders the decoded type-signature surface and asserts byte-for-byte agreement with tools/lf-oracle/LfOracle.scala, which reads the same DAR through com.daml:daml-lf-archive-reader (the decoder Canton itself uses). No JVM is required to use the SDK or the codegen — the oracle is dev/CI-only.

Structs§

Dar
A parsed DAR: its manifest fields plus the raw bytes of each .dalf.

Enums§

DarError
An error opening or reading a DAR.
DecodeError
An error decoding Daml-LF package bytes.

Functions§

decode_all
Decode every package in a DAR, each paired with its package id (archive hash) — the PackageMap for resolving cross-package references.
decode_main_package
Decode the DAR’s main package into the Daml-LF 2 AST, together with its package id (the Archive hash — the input to SCU/PackageMap and to qualifying cross-package references).
decode_package
Decode a single package’s .dalf bytes (an Archive) into the LF 2 AST and its package id (the archive hash).
decode_payload
Decode an ArchivePayload — the inner half of an archive, without the hash beside it.
imported_package_id
Resolve a package_import_id — an index into the package’s explicit import table (package_imports.imported_packages) — to the target package’s id hash. Newer LF (2.dev / SDK 3.5+) references imported packages this way instead of by an interned id string.
interned_dotted_name
Resolve an interned dotted name (a module or type name) to its .-joined form, e.g. "Licensing.AppInstall".
interned_str
Resolve an interned string by its i32 index into a package’s interned_strings table.
interned_type
Resolve an interned type by its i32 index into a package’s interned_types table (LF 2.x stores types once and references them by index).
package_name
The package name from its metadata (PackageMetadata.name_interned_str).
package_version
The package version from its metadata (PackageMetadata.version_interned_str).