Explorer

cbor.read-items

description
Read count items of a CBOR array from offset. Reads halves and concatenates them so that it does not copy the list for each item
type
Fn(bytes: List<Number>, offset: Number, count: Number) -> Union{#none, #some(@cbor.items-at)}
expression
fn(bytes$0, offset$1, count$2) =>
  match @core.less-than(left: $2, right: 2) {
    true =>
      match @core.equal(left: $2, right: 1) {
        true =>
          match @cbor.read(bytes: $0, offset: $1) {
            #some(item$3) =>
              #some({items: [$3.value], next: $3.next}),
            #none(_) =>
              #none
          },
        false =>
          #some({items: [], next: $1})
      },
    false =>
      let half$4 = @core.divide(left: $2, right: 2);
      match @cbor.read-items(bytes: $0, offset: $1, count: $4) {
        #some(left$5) =>
          match @cbor.read-items(bytes: $0, offset: $5.next, count: @core.minus(left: $2, right: $4)) {
            #some(right$6) =>
              #some({items: @core.list-concat(left: $5.items, right: $6.items), next: $6.next}),
            #none(_) =>
              #none
          },
        #none(_) =>
          #none
      }
  }
visibility
public
cbor.read-items (project cbor, branch main, snapshot 5bvML2Im-osGmgnKJsp0FwmfSMONephnrgdWQboV3-E)
id: Mq3gtnuaVhPHcAGZ70-n0_x30qLqGrpxctoEpkqptjU
content hash: Or_zk8HKDsWd9tZdPdp2JAawtih-c6p_XMCZpwO1GN4