Explorer

cbor.read-entries

description
Read count entries of a CBOR map from offset, reading halves
type
Fn(bytes: List<Number>, offset: Number, count: Number) -> Union{#none, #some(@cbor.entries-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(key$3) =>
              match @cbor.read(bytes: $0, offset: $3.next) {
                #some(value$4) =>
                  #some({entries: [{key: $3.value, value: $4.value}], next: $4.next}),
                #none(_) =>
                  #none
              },
            #none(_) =>
              #none
          },
        false =>
          #some({entries: [], next: $1})
      },
    false =>
      let half$5 = @core.divide(left: $2, right: 2);
      match @cbor.read-entries(bytes: $0, offset: $1, count: $5) {
        #some(left$6) =>
          match @cbor.read-entries(bytes: $0, offset: $6.next, count: @core.minus(left: $2, right: $5)) {
            #some(right$7) =>
              #some({entries: @core.list-concat(left: $6.entries, right: $7.entries), next: $7.next}),
            #none(_) =>
              #none
          },
        #none(_) =>
          #none
      }
  }
visibility
public
cbor.read-entries (project cbor, branch main, snapshot 5bvML2Im-osGmgnKJsp0FwmfSMONephnrgdWQboV3-E)
id: yrWEHAmmhpLdpy7SgnE5kZQKmHD5ldCCCeFk7-LKovk
content hash: uQh5yGbqgSB-r98Pqq0rsoFtJR7fX9FCIIk08dEKjMw