Explorer

cbor.head

description
Read the initial byte and argument of the CBOR data item at offset. none if it is cut or has an indefinite length
type
Fn(bytes: List<Number>, offset: Number) -> Union{#none, #some(@cbor.head-info)}
expression
fn(bytes$0, offset$1) =>
  match @core.list-get(list: $0, index: $1) {
    #none(_) =>
      #none,
    #some(initial$2) =>
      let major$3 = @core.shift-right(left: $2, right: 5);
      let info$4 = @core.bit-and(left: $2, right: 31);
      let start$5 = @core.plus(left: $1, right: 1);
      match @core.less-than(left: $4, right: 24) {
        true =>
          #some({major: $3, info: $4, argument: $4, next: $5}),
        false =>
          let count$6 = match $4 {
              24 =>
                1,
              25 =>
                2,
              26 =>
                4,
              27 =>
                8,
              _ =>
                0
            };
          match @core.equal(left: $6, right: 0) {
            true =>
              #none,
            false =>
              match @cbor.uint(bytes: $0, offset: $5, count: $6, acc: 0) {
                #some(argument$7) =>
                  #some({major: $3, info: $4, argument: $7, next: @core.plus(left: $5, right: $6)}),
                #none(_) =>
                  #none
              }
          }
      }
  }
visibility
public
cbor.head (project cbor, branch main, snapshot 5bvML2Im-osGmgnKJsp0FwmfSMONephnrgdWQboV3-E)
id: jO7NKk2MCFq5qnU8f7izJEiKBUhaC8rXHssLpztabJE
content hash: JAS9KSI5omplaNjQ1yrn2hffHJmZMW21F2yJp6eEJGI