Explorer

definy.cbor-to-json

description
CBOR as JSON for the RPC handlers written for JSON: bytes are Base64 strings (as in the JSON of Connect-RPC), tags are their values, floats are null
type
Fn(item: @cbor.item) -> @definy.json
expression
fn(item$0) =>
  match $0 {
    #integer(value$1) =>
      #number<@definy.json>($1),
    #bytes(bytes$2) =>
      #string<@definy.json>(@std.bytes-to-base64(bytes: $2)),
    #text(text$3) =>
      #string<@definy.json>($3),
    #array(items$4) =>
      #array<@definy.json>(@core.list-map(
        T: @cbor.item,
        U: @definy.json,
        f: fn(item$5) =>
          @definy.cbor-to-json(item: $5),
        xs: $4
      )),
    #map(entries$6) =>
      #object<@definy.json>(@core.list-map(
        T: @cbor.entry,
        U: Record{key: String, value: @definy.json},
        f: fn(item$7) =>
          {key: @cbor.key-string(key: $7.key), value: @definy.cbor-to-json(item: $7.value)},
        xs: $6
      )),
    #tagged(tagged$8) =>
      @definy.cbor-to-json(item: $8.value),
    #simple(value$9) =>
      match $9 {
        20 =>
          #boolean<@definy.json>(false),
        21 =>
          #boolean<@definy.json>(true),
        _ =>
          #null<@definy.json>
      },
    #float(_) =>
      #null<@definy.json>
  }
visibility
public
definy.cbor-to-json (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: Wqxo_afX50kL-ax3zt5aofbzaNGDy3nYLm-P6H7WUE8
content hash: qg-bou-ffM4zVhCVeCU7_YrXVzMWJj1922hlzFpbv0Q