1 import Base 2 import ./Protocol.bend as Protocol 3 4 # Reports one representable count update or exhaustion of the backup format. 5 type Decision is Data: 6 CountContinue{next_count: U32} 7 CountLimit{} 8 9 # Increments a cursor count without wrapping its fixed-width representation. 10 def next.checked(count: U32, maximum: Bool) -> Decision: 11 match maximum: 12 case True{}: CountLimit{} 13 case False{}: CountContinue{U32.from_nat(Nat.add(U32.to_nat(count), 1n))} 14 15 def next.copies(copies: U32 & U32 & U32) -> Decision: 16 match copies: 17 case (retained, (checked, _)): 18 next.checked(retained, U32.is_eq(checked, 4294967295)) 19 20 # Advances a cursor count without wrapping past its representable limit. 21 def next(count: U32) -> Decision: 22 next.copies(Protocol.u32.duplicate.triple(count)) 23 24 def u32.pair.copied(copies: U32 & U32 & U32) -> U32 & U32: 25 match copies: 26 case (first, (second, _)): (first, second) 27 28 def u32.pair(value: U32) -> U32 & U32: 29 u32.pair.copied(Protocol.u32.duplicate.triple(value))