~/bend-docscommunity

pure.bend checks

raw source on the hub · import bend-kit-journal@0.4.0.1/pure.bend as Pure

Pure journal framing, recovery, and list model.

3 imports
import Base
import bend-kit-bytes@0.3.3.2/bytes.bend as Bytes
import bend-kit-hash@0.3.2.3/hash.bend as Hash

Types

type Tail source · line 13 · raw

Data

Clean: the input ends on a frame boundary. Torn: the input ends inside a frame. A crash cut the last append short. Corrupt: a whole header or a whole frame fails its check. Recovery does not go past it.

type Step source · line 19 · raw

@-P:Type -> @-S:Type -> Type

One decoding step. Short, Bad, and End give the input back untouched, at the frame start.

type Recovery source · line 26 · raw

@-a:Quant -> @-P:Kind(a) -> @-S:Type -> Type

The committed records in order, how the input ends, and the input from the first frame not taken.

type Replay source · line 30 · raw

@-A:Type -> @-S:Type -> Type

The state after every committed record, how the input ends, and the input from the first frame not taken.

type Cur source · line 218 · raw

Type

The Bytes instance. A cursor reads b from pos; pos only moves forward, past whole frames.

Definitions

def list.fits source · line 164 · raw

@xs:List<&2, U32> -> @+at:U32 -> @+n:U32 -> Pair(List<&2, U32>, Bool)

def list.field source · line 168 · raw

@xs:List<&2, U32> -> U32

def list.u32 source · line 175 · raw

@xs:List<&2, U32> -> @+at:U32 -> Pair(List<&2, U32>, U32)

def list.cut source · line 179 · raw

@xs:List<&2, U32> -> @+hs:U32 -> @+len:U32 -> Pair(List<&2, U32>, List<&2, U32>)

def list.skip source · line 183 · raw

@xs:List<&2, U32> -> @+hs:U32 -> @+len:U32 -> List<&2, U32>

def list.crc source · line 187 · raw

@xs:List<&2, U32> -> U32

CRC-32 (ISO-HDLC, as zlib and Hash.crc32) of a list of octets.

def list.sum source · line 190 · raw

@xs:List<&2, U32> -> Pair(List<&2, U32>, U32)

def list.next source · line 194 · raw

@+max:U32 -> @xs:List<&2, U32> -> Step<List<&2, U32>, List<&2, U32>>

def list.recover source · line 197 · raw

@n:Nat -> @+max:U32 -> @xs:List<&2, U32> -> Recovery<&2, List<&2, U32>, List<&2, U32>>

def list.head source · line 203 · raw

@+len:U32 -> @+sum:U32 -> List<&2, U32>

def list.frame source · line 206 · raw

@+p:List<&2, U32> -> List<&2, U32>

def list.log source · line 210 · raw

@rs:List<&2, List<&2, U32>> -> List<&2, U32>

The frames of rs, one after another: what appending each record writes.

def cur.fits source · line 221 · raw

@c:Cur -> @+at:U32 -> @+n:U32 -> Pair(Cur, Bool)

def cur.field source · line 225 · raw

@m:Maybe<&2, U32> -> U32

def cur.u32.fin source · line 232 · raw

@+pos:U32 -> @r:Pair(0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes, Maybe<&2, U32>) -> Pair(Cur, U32)

def cur.u32 source · line 236 · raw

@c:Cur -> @+at:U32 -> Pair(Cur, U32)

def cur.cut.fin source · line 240 · raw

@+pos:U32 -> @r:Pair(0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes, 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes) -> Pair(Cur, 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes)

def cur.cut source · line 244 · raw

@c:Cur -> @+hs:U32 -> @+len:U32 -> Pair(Cur, 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes)

def cur.skip source · line 248 · raw

@c:Cur -> @+hs:U32 -> @+len:U32 -> Cur

def cur.sum source · line 252 · raw

@p:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> Pair(0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes, U32)

def fuel source · line 256 · raw

@+len:U32 -> Nat

Every frame of b holds at least 12 octets, so len / 12 + 1 steps reach the end.

def frame.of source · line 264 · raw

@+len:U32 -> @r:Pair(0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes, U32) -> 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes

def frame source · line 269 · raw

@p:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes

The frame that appending p writes.

Templates

template next.verdict source · line 37 · raw

@-P:Type -> @-S:Type -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @ok:Bool -> @+len:U32 -> @s:S -> @p:P -> Step<P, S>

template next.summed source · line 44 · raw

@-P:Type -> @-S:Type -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @+want:U32 -> @+len:U32 -> @s:S -> @r:Pair(P, U32) -> Step<P, S>

template next.cut source · line 48 · raw

@-P:Type -> @-S:Type -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+want:U32 -> @+len:U32 -> @r:Pair(S, P) -> Step<P, S>

template next.want source · line 52 · raw

@-P:Type -> @-S:Type -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+len:U32 -> @r:Pair(S, U32) -> Step<P, S>

template next.body source · line 56 · raw

@-P:Type -> @-S:Type -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+len:U32 -> @r:Pair(S, Bool) -> Step<P, S>

template next.size source · line 64 · raw

@-P:Type -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @over:Bool -> @+len:U32 -> @s:S -> Step<P, S>

template next.head source · line 71 · raw

@-P:Type -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @ok:Bool -> @+max:U32 -> @+len:U32 -> @s:S -> Step<P, S>

template next.lenx source · line 78 · raw

@-P:Type -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+max:U32 -> @+len:U32 -> @r:Pair(S, U32) -> Step<P, S>

template next.len source · line 82 · raw

@-P:Type -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+max:U32 -> @r:Pair(S, U32) -> Step<P, S>

template next.start source · line 88 · raw

@-P:Type -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+max:U32 -> @r:Pair(S, Bool) -> Step<P, S>

The two length fields are checked before the payload is waited for, so a damaged length is Bad and never a Torn tail that hides the frames after it.

template next.any source · line 96 · raw

@-P:Type -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+max:U32 -> @r:Pair(S, Bool) -> Step<P, S>

template next source · line 105 · raw

@-P:Type -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @+max:U32 -> @s:S -> Step<P, S>

One frame from s. max caps a payload's length.

template recover.con source · line 108 · raw

@-a:Quant -> @-P:Kind(a) -> @-S:Type -> @p:P -> @r:Recovery<a, P, S> -> Recovery<a, P, S>

template recover.go source · line 114 · raw

@-a:Quant -> @-P:Kind(a) -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @n:Nat -> @+max:U32 -> @st:Step<P, S> -> Recovery<a, P, S>

Every frame from st on. Once n frames are taken, the next one is the last: the tail is Corrupt, and rest starts after it. Callers give n at least the frame count, so this never happens.

template recover source · line 134 · raw

@-a:Quant -> @-P:Kind(a) -> @-S:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @n:Nat -> @+max:U32 -> @s:S -> Recovery<a, P, S>

Every committed record of s, in order.

template replay.go source · line 138 · raw

@-P:Type -> @-S:Type -> @-A:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @-step:(@_:A -> @_:P -> A) -> @n:Nat -> @+max:U32 -> @st:Step<P, S> -> @acc:A -> Replay<A, S>

step folded over every frame from st on, without a list of the records. n as in recover.go.

template replay source · line 157 · raw

@-P:Type -> @-S:Type -> @-A:Type -> @-fits:(@_:S -> @+at:U32 -> @+n:U32 -> Pair(S, Bool)) -> @-u32:(@_:S -> @+at:U32 -> Pair(S, U32)) -> @-cut:(@_:S -> @+hs:U32 -> @+len:U32 -> Pair(S, P)) -> @-skip:(@_:S -> @+hs:U32 -> @+len:U32 -> S) -> @-sum:(@_:P -> Pair(P, U32)) -> @-step:(@_:A -> @_:P -> A) -> @n:Nat -> @+max:U32 -> @s:S -> @acc:A -> Replay<A, S>

template list.replay source · line 200 · raw

@-A:Type -> @-step:(@_:A -> @_:List<&2, U32> -> A) -> @n:Nat -> @+max:U32 -> @xs:List<&2, U32> -> @acc:A -> Replay<A, List<&2, U32>>

template replay.bytes source · line 260 · raw

@-A:Type -> @-step:(@_:A -> @_:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> A) -> @+max:U32 -> @b:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @acc:A -> Replay<A, Cur>

step folded over every committed record of b, in order. rest.pos is where the committed prefix ends.