Explorer

cbor.read

description
Read the CBOR data item at offset (docs.cbor). none if it is not CBOR definy reads
type
Fn(bytes: List<Number>, offset: Number) -> Union{#none, #some(@cbor.item-at)}
expression
fn(bytes$0, offset$1) =>
  match @cbor.head(bytes: $0, offset: $1) {
    #none(_) =>
      #none,
    #some(head$2) =>
      let end$3 = @core.plus(left: $2.next, right: $2.argument);
      let fits$4 = @core.not(value: @core.less-than(left: @core.list-length(value: $0), right: $3));
      match $2.major {
        0 =>
          #some({value: #integer<@cbor.item>($2.argument), next: $2.next}),
        1 =>
          #some({value: #integer<@cbor.item>(@core.minus(left: -1, right: $2.argument)), next: $2.next}),
        2 =>
          match $4 {
            true =>
              #some({
                value: #bytes<@cbor.item>(@std.list-range(T: Number, list: $0, start: $2.next, end: $3)),
                next: $3
              }),
            false =>
              #none
          },
        3 =>
          match $4 {
            true =>
              #some({
                value: #text<@cbor.item>(@std.bytes-to-string-range(bytes: $0, start: $2.next, end: $3)),
                next: $3
              }),
            false =>
              #none
          },
        4 =>
          match @cbor.read-items(bytes: $0, offset: $2.next, count: $2.argument) {
            #some(items$5) =>
              #some({value: #array<@cbor.item>($5.items), next: $5.next}),
            #none(_) =>
              #none
          },
        5 =>
          match @cbor.read-entries(bytes: $0, offset: $2.next, count: $2.argument) {
            #some(entries$6) =>
              #some({value: #map<@cbor.item>($6.entries), next: $6.next}),
            #none(_) =>
              #none
          },
        6 =>
          match @cbor.read(bytes: $0, offset: $2.next) {
            #some(item$7) =>
              #some({value: #tagged<@cbor.item>({tag: $2.argument, value: $7.value}), next: $7.next}),
            #none(_) =>
              #none
          },
        _ =>
          match @core.less-than(left: $2.info, right: 25) {
            true =>
              #some({value: #simple<@cbor.item>($2.argument), next: $2.next}),
            false =>
              #some({value: #float<@cbor.item>({info: $2.info, bits: $2.argument}), next: $2.next})
          }
      }
  }
visibility
public
cbor.read (project cbor, branch main, snapshot 5bvML2Im-osGmgnKJsp0FwmfSMONephnrgdWQboV3-E)
id: -zZh99nhRuSusDSYEBauBplwyJoQS9t79htrdcp9rJc
content hash: -t7ML9bYgA0cVR8pGaD8L5Lf91rGLZ-YLxjPmKbOy7w