LegacyWal.walk: def of mylsm-lsm-store@0.6.0.1 Import: import mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend as LegacyWal Lines 129-209 of mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend: https://jend.leeeet.dev/read.txt?path=mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend&start_line=129&end_line=209 import Base import mylsm-lsm-store@0.6.0.1/src/coordinator/QueuePolicy.bend as QueuePolicy import mylsm-lsm-store@0.6.0.1/src/Wal.bend as Wal import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes # Applies one pure parser transition, rejecting malformed or truncated frames. def walk(fuel: Nat, state: WalkState) -> VerifyResult: match fuel: case 0n: WalInvalid{} case 1n+rest: match state: case Header{pair}: match pair: case (source, header): walk(rest, HeaderDecoded{source, Wal.decode_header(header)}) case HeaderDecoded{source, result}: match result: case Fail{_}: WalInvalid{} case Done{Unit{}}: walk(rest, HeaderMeasured{Bytes.length(source)}) case HeaderMeasured{pair}: match pair: case (source, size): walk(rest, HeaderSeek{ Bytes.Cursor.seek(Bytes.Cursor.new(source), 8)}) case HeaderSeek{pair}: match pair: case (_, False{}): WalInvalid{} case (cursor, True{}): walk(rest, Read{cursor, 0n}) case Read{cursor, frames}: walk(rest, Remaining{Bytes.Cursor.remaining(cursor), frames}) case Remaining{pair, frames}: match pair: case (cursor, remaining): walk(rest, Empty{cursor, U32.to_nat(remaining), frames}) case Empty{cursor, remaining, frames}: walk(rest, walk.empty.checked(cursor, frames, QueuePolicy.nat.clone.pair(remaining))) case EmptyChecked{cursor, remaining, frames, empty}: match empty: case True{}: walk(rest, Finish{frames}) case False{}: walk(rest, walk.length.checked(cursor, frames, QueuePolicy.nat.clone.pair(remaining))) case HasLength{cursor, remaining, frames, has_length}: match has_length: case False{}: WalInvalid{} case True{}: walk(rest, Length{Bytes.Cursor.u32be(cursor), U32.from_nat(Nat.sub(remaining, 4n)), frames}) case Length{pair, remaining, frames}: match pair: case (_, None{}): WalInvalid{} case (cursor, Some{length}): walk(rest, walk.length.validated(cursor, remaining, frames, length)) case Bounds{cursor, length, frames, valid}: match valid: case False{}: WalInvalid{} case True{}: walk(rest, walk.position.state(cursor, frames, QueuePolicy.nat.clone.pair(U32.to_nat(length)))) case Position{cursor, positions, frame_bytes, frame_length, frames}: match cursor: case Bytes.Cursor{bytes, _, _, _}: match positions: case (start_nat, end_nat): +start = U32.from_nat(Nat.sub(start_nat, 4n)) +end = U32.add(U32.from_nat(end_nat), frame_length) walk(rest, Frame{Bytes.slice(bytes, start, frame_bytes), end, frames}) case Frame{pair, end, frames}: match pair: case (source, frame): walk(rest, Decoded{Wal.decode_frame(frame), source, end, frames}) case Decoded{result, source, end, frames}: match result: case Fail{_}: WalInvalid{} case Done{_}: walk(rest, Seek{Bytes.Cursor.seek(Bytes.Cursor.new(source), end), Nat.add(frames, 1n)}) case Seek{pair, frames}: match pair: case (_, False{}): WalInvalid{} case (cursor, True{}): walk(rest, Read{cursor, frames}) case Finish{frames}: WalValid{frames} case Invalid{}: WalInvalid{} Uses (27): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.from_nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.to_nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Unit https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Cursor https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Cursor.new https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Cursor.remaining https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Cursor.seek https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Cursor.u32be https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=length https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=slice https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Wal.bend&name=decode_frame https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Wal.bend&name=decode_header https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/coordinator/QueuePolicy.bend&name=nat.clone.pair https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend&name=VerifyResult https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend&name=WalkState https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend&name=walk.empty.checked https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend&name=walk.length.checked https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend&name=walk.length.validated https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/transfer/LegacyWal.bend&name=walk.position.state