Skip to content

MCMS Custom codec for complex custom types#24

Draft
JohnChangUK wants to merge 1 commit intomainfrom
mcms-codec
Draft

MCMS Custom codec for complex custom types#24
JohnChangUK wants to merge 1 commit intomainfrom
mcms-codec

Conversation

@JohnChangUK
Copy link
Contributor

Add Daml Codec Generator

Auto-generate *CodecGen.daml files from *Types.daml source files, eliminating hand-written codec boilerplate.

How it works

LRPoolTypes.daml → go run ./contracts/cmd/damlcodecs → LRPoolTypesCodecGen.daml

The generator:

  1. Parses *Types.daml files to extract record/variant definitions
  2. Maps each field type to its encode/decode function
  3. Outputs a complete codec file

Type resolution:

  • Primitives (Int, Bool, Numeric 0, etc.) → built-in codec functions
  • Records/variants in same file → generates codecs for them automatically
  • External types (RawInstanceAddress, InstrumentId, CustomContext) → configured via customCodecs map

Usage

  1. cd <your_repo>
  2. go run ./contracts/cmd/damlcodecs
  3. daml build --all

Files added

go-daml:

  • codegen/damlparser/ - Parses Daml source files
  • codegen/damltemplate/ - Generates codec output

<your_repo>:

  • contracts/cmd/damlcodecs/main.go - CLI tool with project-specific config

Why parse source files?

Daml compiles packages atomically. The codec imports the types, so you can't compile types without the codec existing. Parsing source files (not compiled DARs) breaks this circular dependency.

@JohnChangUK JohnChangUK requested a review from a team as a code owner March 27, 2026 04:37
@github-actions
Copy link

👋 JohnChangUK, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@JohnChangUK JohnChangUK marked this pull request as draft March 27, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant