Explorer

definy.cbor-to-value

description
CBOR as core.value (docs/cbor.md): a map with only one key that starts with # is a variant, other maps are records. Bytes, tags, null and floats are unit
type
Fn(cbor: @cbor.item) -> @core.value
expression
fn(cbor$0) =>
  match $0 {
    #integer(number$1) =>
      #number<@core.value>($1),
    #text(text$2) =>
      #string<@core.value>($2),
    #array(items$3) =>
      #list<@core.value>(@core.list-map(
        T: @cbor.item,
        U: @core.value,
        f: fn(item$4) =>
          @definy.cbor-to-value(cbor: $4),
        xs: $3
      )),
    #map(entries$5) =>
      match @definy.cbor-variant-tag(entries: $5) {
        #some(tag$6) =>
          match @core.list-get(list: $5, index: 0) {
            #some(entry$7) =>
              #variant<@core.value>({tag: $6, payload: @definy.cbor-to-value(cbor: $7.value)}),
            #none(_) =>
              #unit<@core.value>
          },
        #none(_) =>
          #record<@core.value>(@core.list-map(
            T: @cbor.entry,
            U: Record{key: String, value: @core.value},
            f: fn(item$8) =>
              {key: @cbor.key-string(key: $8.key), value: @definy.cbor-to-value(cbor: $8.value)},
            xs: $5
          ))
      },
    #simple(code$9) =>
      match $9 {
        20 =>
          #boolean<@core.value>(false),
        21 =>
          #boolean<@core.value>(true),
        _ =>
          #unit<@core.value>
      },
    _ =>
      #unit<@core.value>
  }
visibility
public
definy.cbor-to-value (project definy, branch release-time-compare, snapshot JJrRgQW_LZN6tN8CbYr1dN7HosqNTuIWWYx7ACbt1n0)
id: JpRGXIktqb4KoNemZRik1ry8hj-ndnPGl4k-8VlQM3U
content hash: PZy0ACEI9VimtOeEH0oAOVE3DtqxYJJiZ29KeTySu5k