def restore.loop
mylsm-lsm-store@0.6.0.1 · src/transfer/Restore.bend:836
import mylsm-lsm-store@0.6.0.1/src/transfer/Restore.bend as Restore
import Base
import mylsm-lsm-store@0.6.0.1/src/transfer/RestorePolicy.bend as RestorePolicy
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
836def restore.loop(
837 fuel: Nat,
838 state: State,
839 current: Result<&1, &1, Error, BlockMeta>
840) -> Result<&1, &1, Error, Decoded>:
841 match fuel:
842 case 0n: Fail{InvalidFormat{}}
843 case 1n+fuel_rest:
844 match state:
845 case State{input, +offset, entry_count, block_count, +remaining_blocks,
846 +block_index, +decoded_count, reversed}:
847 match input:
848 case (for_size, retained):
849 match remaining_blocks:
850 case 0n: Fail{InvalidFormat{}}
851 case 1n+rest:
852 match rest:
853 case 0n:
854 match current:
855 case Fail{error}: Fail{error}
856 case Done{block}:
857 match block:
858 case BlockMeta{_, _, _, _, +record_count, +block_length, entries}:
859 +next_offset = Nat.add(offset, block_length)
860 +next_count = Nat.add(decoded_count, record_count)
861 next_reversed = restore.prepend.entries(entries, reversed)
862 restore.finish(Bytes.length(for_size), next_offset,
863 entry_count, block_count, next_count,
864 next_reversed)
865 case 1n+more:
866 match current:
867 case Fail{error}: Fail{error}
868 case Done{block}:
869 match block:
870 case BlockMeta{_, _, _, _, +record_count, +block_length, entries}:
871 +next_offset = Nat.add(offset, block_length)
872 +next_index = Nat.add(block_index, 1n)
873 +next_count = Nat.add(decoded_count, record_count)
874 next_reversed = restore.prepend.entries(entries, reversed)
875 restore.loop(fuel_rest,
876 State{clone.split(retained), next_offset, entry_count,
877 block_count,
878 RestorePolicy.remaining(
879 RestorePolicy.after_block(remaining_blocks)),
880 next_index, next_count,
881 next_reversed},
882 restore.block.open(for_size, next_offset,
883 U32.from_nat(next_index)))