def decode.records.loop

mylsm-lsm-store@0.6.0.1 · src/ByteWal.bend:799

import mylsm-lsm-store@0.6.0.1/src/ByteWal.bend as ByteWal
import Base
import mylsm-lsm-store@0.6.0.1/src/Wal.bend as Wal

799# Decodes the exact number of records declared by a WAL frame.
800def decode.records.loop(fuel: Nat, state: DecodeState) -> Result<&1, &1, Wal.Error, ParsedBatch>:
801  match fuel:
802    case 0n:
803      Fail{Wal.Malformed{}}
804    case 1n+rest:
805      match state:
806        case DecodeNext{frame, offset, remaining, reversed}:
807          match remaining:
808            case 0n:
809              Done{ParsedBatch{offset, Batch{List.reverse(&1, Mutation, reversed)}}}
810            case 1n+more:
811              decode.records.loop(rest,
812                DecodeRead{record.decode(frame, offset), more, reversed})
813        case DecodeRead{record, remaining, reversed}:
814          match record:
815            case RecordError{_, error}:
816              Fail{error}
817            case RecordDone{frame, offset, mutation}:
818              decode.records.loop(rest,
819                DecodeNext{frame, offset, remaining, Con{mutation, reversed}})

Uses (11)

Used by (1)