@decco Variant encoding

Is there an easy way to skip the array on encode?

@decco
type order = {
  name: string,
}

@decco
type rule =
  | Order(order)

Default:

//rule_encode
["Order", {name: "John Smith"}]

Needed:

//rule_encode
{name: "John Smith"}

Not exactly sure how to accomplish this with a custom codec or if that is the best way to achieve this.

Perhaps use order_encode? Note it depends on the full semantics of your actual type and how it needs to be encoded and decoded in the real codebase. From the simplified example it’s not really possible to tell.

Maybe it helps to parse into variant. https://github.com/green-labs/ppx_spice

1 Like