Explorer

core.decode-value-at

description
Reads a value written by core.encode-value from index on in text (bytes are text's bytes). next is the index after it. none if it is not written that way
type
Fn(text: String, bytes: List<Number>, index: Number) -> Union{#none, #some(Record{value: @core.value, next: Number})}
expression
fn(text$0, bytes$1, index$2) =>
  let next$3 = @core.plus(left: $2, right: 1);
  match @core.less-than(left: $2, right: @core.list-length(value: $1)) {
    false =>
      #none,
    true =>
      match @core.string-slice(value: $0, start: $2, end: $3) {
        "n" =>
          match @core.decode-number-until(bytes: $1, index: $3, end: 59) {
            #some(number$4) =>
              #some({value: #number<@core.value>($4.value), next: $4.next}),
            #none(_) =>
              #none
          },
        "s" =>
          match @core.decode-number-until(bytes: $1, index: $3, end: 58) {
            #some(length$5) =>
              let end$6 = @core.plus(left: $5.next, right: $5.value);
              match @core.less-than-or-equal(left: $6, right: @core.list-length(value: $1)) {
                true =>
                  #some({value: #string<@core.value>(@core.string-slice(value: $0, start: $5.next, end: $6)), next: $6}),
                false =>
                  #none
              },
            #none(_) =>
              #none
          },
        "t" =>
          #some({value: #boolean<@core.value>(true), next: $3}),
        "f" =>
          #some({value: #boolean<@core.value>(false), next: $3}),
        "u" =>
          #some({value: #unit<@core.value>, next: $3}),
        "l" =>
          match @core.decode-number-until(bytes: $1, index: $3, end: 58) {
            #some(count$7) =>
              match @core.decode-value-items(text: $0, bytes: $1, index: $7.next, count: $7.value, items: []) {
                #some(items$8) =>
                  #some({value: #list<@core.value>($8.items), next: $8.next}),
                #none(_) =>
                  #none
              },
            #none(_) =>
              #none
          },
        "r" =>
          match @core.decode-number-until(bytes: $1, index: $3, end: 58) {
            #some(count$9) =>
              match @core.decode-value-fields(text: $0, bytes: $1, index: $9.next, count: $9.value, fields: []) {
                #some(fields$10) =>
                  #some({value: #record<@core.value>($10.fields), next: $10.next}),
                #none(_) =>
                  #none
              },
            #none(_) =>
              #none
          },
        "v" =>
          match @core.decode-value-at(text: $0, bytes: $1, index: $3) {
            #some(tag$11) =>
              match $11.value {
                #string(name$12) =>
                  match @core.decode-value-at(text: $0, bytes: $1, index: $11.next) {
                    #some(payload$13) =>
                      #some({value: #variant<@core.value>({tag: $12, payload: $13.value}), next: $13.next}),
                    #none(_) =>
                      #none
                  },
                _ =>
                  #none
              },
            #none(_) =>
              #none
          },
        _ =>
          #none
      }
  }
visibility
public
core.decode-value-at (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: o2KO5ycepOIvILKJ9WIMXRwafEYlQ4cH0cDGHQLuKCM
content hash: XL5JyxBtOZIiupLMQ7JilC16F_BJyeg7rjEJRyuxV70